Same Apple-design copy pass as the OAuth consent screen: "Held pushes -- all repos" -> "Held pushes, all repos", dropped redundant "so X is a single click -- no token to copy or paste" trailers now that the consent screen itself says that, and the device sign-in page's raw space- separated scope list is now a one-line summary + an expandable <details> for the full list (matching grant.tmpl's own pattern). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rithub-device-auth
Real browser sign-in for rit login (RIT-ACT, 2026-12-01). Rithub previously
had no OAuth2 device-code flow (/login/oauth/device is a plain 404 on the
engine) -- rit login could only open the token-settings page and have a
human paste a personal access token. This service adds the real thing: an
RFC-8628-shaped device-authorization flow, wrapping the engine's own real
OAuth2 "Rit CLI" application (confirmed registered 2026-11-18, extended this
pass with a second redirect_uri) rather than inventing a second, parallel
identity system.
Routes (proxied by Caddy on rithub.dev)
POST /api/rit/device/code--rit logincalls this first. Returns{device_code, user_code, verification_uri, verification_uri_complete, expires_in, interval}.GET /device[?code=XXXX-XXXX]-- the human-facing confirmation page, in Rithub's own chrome (reuses the engine's real nav/footer markup and stylesheets, same technique asrithub-outage-protect). Requires an existing rithub.dev session cookie; redirects to/user/loginotherwise. Lists the exact scopes being granted.GET /device/authorize?user_code=...-- generates a PKCE pair, stores the verifier server-side, 302s into the engine's own real/login/oauth/authorize(native consent screen, session-cookie authenticated by the engine itself).GET /api/rit/device/callback-- the engine's OAuth2 redirect target. Exchanges the authorization code for a real access token via/login/oauth/access_token, authenticated with the PKCE verifier (no client secret -- the "Rit CLI" app is a public/non-confidential client).POST /api/rit/device/token-- polled byrit login:authorization_pending/slow_down/expired_token/access_denied/{access_token, token_type, scope}(single-use: a device_code can only ever be exchanged for its token once).
Security notes
- Only a SHA-256 hash of each
device_codeis ever stored (src/store.mjs) -- the raw value is handed to the CLI once and never written anywhere else. The 8-charuser_codeexcludes visually ambiguous characters (0/O, 1/I/L). - Every record expires after 10 minutes and is in-memory only (a restart simply fails in-flight sign-ins the same way an expiry would).
- The OAuth
stateparameter reused as the correlator is the device_code's hash, not the raw code -- the browser never sees the value the CLI is polling with. - Polling is rate-limited to roughly one request every 4 seconds per
device_code (
slow_down). - The resulting token is a real engine OAuth2 access token scoped to
exactly
read:repository write:repository read:issue write:issue read:organization write:organization read:user write:user read:package write:package(src/ritOAuth.mjs) -- never broader than whatritactually uses. - This service never has the user's password and never impersonates a
user server-side (
sudo/admin-token tricks) -- it only accepts a token the engine itself minted after that exact human approved that exact scope list in their own browser session.
Engine-side change made alongside this service (2026-12-01)
[oauth2] ACCESS_TOKEN_EXPIRATION_TIME = 2592000added to the engine'sapp.ini(was unset, default 3600s/1h) -- shared by every OAuth2 app on this instance including Ritgram's "Sign in with Rithub", but harmless there since Ritgram re-authenticates on every sign-in anyway. Without this, arit loginsession would silently die after an hour with no refresh-token plumbing in the CLI yet.- The pre-existing "Rit CLI" OAuth2 application (id 5, registered
2026-11-18 for a loopback-redirect flow that was apparently never
finished) was extended via
PATCH /api/v1/user/applications/oauth2/5to addhttps://rithub.dev/api/rit/device/callbackas a second redirect_uri, alongside its existinghttp://127.0.0.1:42813/callback(kept, not removed).
Deploy
Same convention as rithub-outage-protect/rithub-billing: rsync/scp
this directory to the box, pm2 start ecosystem.config.cjs (or pm2 reload rithub-device-auth), add Caddy handle /device* and handle /api/rit/device* blocks proxying to 127.0.0.1:3357, reload Caddy.