feat(cli): add 'qr' command for transferring API token to mobile apps#545
Open
eugenn wants to merge 1 commit into
Open
feat(cli): add 'qr' command for transferring API token to mobile apps#545eugenn wants to merge 1 commit into
eugenn wants to merge 1 commit into
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
tokscale qrsubcommand that renders the locally saved API token (from~/.config/tokscale/credentials.json) as a QR code directly in the terminal. The QR payload is a JSON blob containing both the token and the username, so a companion app can authenticate and identify the user from a single scan.Why
Tokscale is desktop-first today, but the account/leaderboard is a natural fit for a companion mobile app (on-the-go leaderboard, weekly summary push notifications, badge sharing, etc.). Mobile apps need a frictionless way to log in — typing a 50+ char
tt_xxxtoken on a phone keyboard, or running the browser device-code flow a second time on mobile, is exactly the kind of paper-cut that kills a companion-app funnel.Today's options are all unergonomic:
tt_tokens are 50+ characters; mobile keyboards make this miserable and error-prone.A QR code displayed by the already-trusted CLI is the de-facto standard for this exact problem (Discord, Signal, WhatsApp Web, GitHub CLI device flow all do variants of it):
tokscale qron the machine where they already authenticated viatokscale login.JSON (not bare token, not URL) was chosen for the payload so mobile apps can also display the username next to the avatar before activating the session — i.e. show a
Sign in as @eugenn?confirmation step, which is a meaningful safety check when the QR may have been displayed on a screen the user no longer fully controls.What changed
tokscale qrsubcommand wired incrates/tokscale-cli/src/main.rs(added to theCommandsenum and routed toauth::show_qr).auth::show_qr()incrates/tokscale-cli/src/auth.rs:load_credentials()helper. If the user isn't logged in, prints the same hint thatwhoamiuses and exits cleanly (no crash, no error).{"token":"tt_xxx","username":"<name>"}and feeds it toqrcode::QrCode::new.unicode::Dense1x2(two modules per terminal row → compact, square-aspect output). Colors are inverted so the QR is visible on a typical dark terminal background.Token:andUser:plaintext below the QR for fallback / debugging.qrcode = "0.14"added undercrates/tokscale-cli/Cargo.toml. Default features only; no FFI; MIT/Apache-2.0 dual-licensed.No server-side, frontend, or shared-protocol changes. The mobile-app contract is just "scan, parse JSON, use
tokenas bearer" — exactly the auth the CLI itself uses against/api/auth/token.Usage
Decoded QR contents:
{"token":"tt_5be17ed8c9b94...","username":"eugenn"}Validation
cargo build -p tokscale-cli(debug + release) — clean, no new warnings.tokscale qragainst a real credentials file. QR scans cleanly with iOS Camera and yields the expected JSON payload. The "not logged in" branch was exercised by temporarily movingcredentials.jsonout of the way — prints the same hint aswhoami, exits 0.login,logout,whoami,submitetc. are byte-for-byte unchanged.Risk
tokscale qrare entirely unaffected.~/.config/tokscale/credentials.json— no new secret material is created or exposed by this PR. The QR is only ever rendered to the user's own terminal output; there is no networking and no file write.qrcode0.14): pure Rust, no FFI, ~1.5k LOC, widely used.Follow-ups (not in this PR)
/api/auth/tokenvalidator before persisting the token, mirroringlogin_with_tokeninauth.rs.tokscale://login?token=...&username=...once mobile apps register a URL scheme, so iOS/Android can deep-link straight from the system camera without an in-app QR reader.Summary by cubic
Adds a
tokscale qrcommand that displays your saved API token and username as a QR code in the terminal. This enables quick mobile sign-in by scanning one code.New Features
tokscale qr.whoamiand exits.Dense1x2and inverted colors for dark terminals.auth::show_qr()andCommands::Qr; README updated.Dependencies
qrcode0.14 totokscale-cli(pure Rust).Written for commit f4a15ae. Summary will update on new commits.