Skip to content

Device login: the protocol facts, and whether Clerk's machine auth changes anything #116

Closed

Description

@allisonmahmood

Question

patchy login's design is decided — URL plus short code, confirmed in a signed-in browser, the machine named on first login, a Patchy-owned machine token. The earlier device-login research left with its branch; re-gather what the protocol ticket needs:

  1. RFC 8628 as written: user-code alphabet, length and entropy, verification_uri_complete, expiry, interval, the authorization_pending / slow_down / expired_token / access_denied responses, and its rate-limiting and brute-force guidance.
  2. How gh, Claude Code, Codex, Vercel, Fly and Stripe CLIs do it today: code format, expiry, whether the person enters or confirms the code, machine naming, what the confirm page shows — and the device-code phishing incidents that motivated confirm-not-enter.
  3. Clerk's machine auth as it stands: API keys, M2M tokens, OAuth access tokens, acceptsToken; whether Clerk as an OAuth provider offers a device authorization grant. State plainly whether any of it changes the decision to mint Patchy's own token. The decision's reasons were: local verification, no Clerk on the publish path, idle expiry, revoke-on-deactivate, and every version naming the token that published it.

Output: the resolution comment on this ticket, each claim cited. Feeds Device login: the protocol, and the machine token's columns.

Activity

  1. added
    wayfinder:research
    on Sep 2, 2026
  2. allisonmahmood commented on Sep 2, 2026

    @allisonmahmood
    OwnerAuthor

    Resolution

    Research for #116, read on 2026-09-02 from primary sources. Versions read: gh v2.99.0, stripe-cli v1.50.8 (released 2026-09-01), flyctl v0.4.97, codex rust-v0.152.1, vercel 59.11.2, @clerk/backend 3.17.0, clerk-docs main as of 2026-09-01. Nothing here contradicts the decided design; point 3 says why. One precedent moved under us: Stripe's CLI is migrating from a confirm-the-pairing-code flow to a plain RFC 8628 enter-the-code flow (point 2).

    1. RFC 8628 as written

    Source for everything in this section: https://www.rfc-editor.org/rfc/rfc8628.txt.

    Response parameters (§3.2). device_code (REQUIRED), user_code (REQUIRED), verification_uri (REQUIRED, "should be short and easy to remember as end users will be asked to manually type it"), verification_uri_complete (OPTIONAL, "includes the user_code ... designed for non-textual transmission"), expires_in (REQUIRED, "lifetime in seconds of the device_code and user_code"; the RFC's example uses 1800), interval (OPTIONAL, "If no value is provided, clients MUST use 5 as the default"). [§3.2]

    Request (§3.1). client_id REQUIRED for public clients, scope OPTIONAL. Token request (§3.4) uses grant_type=urn:ietf:params:oauth:grant-type:device_code plus device_code and client_id. [§3.1, §3.4]

    User interaction (§3.3, §3.3.1). The server "prompts the end user to identify the device authorization session by entering the user_code" and should "inform the user about the action they are undertaking and ask them to approve or deny the request." Servers "MUST implement a user-interaction sequence that starts with the user navigating to verification_uri and continues with them supplying the user_code at some stage." With verification_uri_complete (QR/NFC/link): "Clients MUST still display the user_code, as the authorization server will require the user to confirm it to disambiguate devices or as remote phishing mitigation (see Section 5.4)" and "the server SHOULD display the user_code to the user and ask them to verify that it matches the user_code being displayed on the device to confirm they are authorizing the correct device." [§3.3, §3.3.1] This is the RFC's own name for the confirm-not-enter design: it is the §3.3.1 optimisation, not a deviation.

    Polling and errors (§3.5). "Before each new request, the client MUST wait at least the number of seconds specified by the interval parameter ... or 5 seconds if none was provided, and respect any increase in the polling interval required by the slow_down error." Errors: authorization_pending ("client SHOULD repeat the access token request"), slow_down ("the interval MUST be increased by 5 seconds for this and all subsequent requests"), expired_token ("the device authorization session has concluded"; client "MAY commence a new device authorization request but SHOULD wait for user interaction before restarting"), access_denied ("The authorization request was denied"). [§3.5]

    User-code alphabet, length, entropy (§6.1). The RFC gives this as "one way", not as a RECOMMENDED profile: restricting to case-insensitive A–Z and "further removing vowels to avoid randomly creating words results in the base 20 character set BCDFGHJKLMNPQRSTVWXZ"; example WDJB-MJHT, "8 significant characters and has dashes added for end-user readability. The resulting entropy is 20^8" (about 34.5 bits). Numeric alternative: 9 digits, 019-450-730, 10^9 (about 29.9 bits). "The server should strip dashes and other punctuation that it added for readability"; input "should be uppercased before a comparison"; stripping all characters outside the chosen set is recommended. The one RECOMMENDED in §6.1 is avoiding character sets "that contain two or more characters that can easily be confused with each other, like 0 and O, or 1, l and I". [§6.1]

    Brute force and rate limiting (§5.1, §5.2). "It is recommended that the server rate-limit user code attempts." The target is a 2^-32 chance of success: "If ... one uses an 8-character base 20 user code (with roughly 34.5 bits of entropy), the rate-limiting interval and validity period would need to only allow 5 attempts in order to get the same 2^-32 probability." Brute-forcing the user code lets the attacker "approve the authorization grant with their own credentials" (the device ends up logged in as the attacker). The device code "is not displayed to the user ... a very high entropy code SHOULD be used." [§5.1, §5.2] Design consequence: in a confirm-not-enter flow nobody types the user code, so the guessable secret is whatever identifies the session in the confirm URL; that id needs device-code-grade entropy (§5.2), and the confirm endpoint still needs a per-session attempt cap.

    Phishing and spying (§5.3–5.6). §5.4: "an attacker might send an email instructing the target user to visit the verification URL and enter the user code ... it is RECOMMENDED to inform the user that they are authorizing a device ... The authorization server SHOULD display information about the device so that the user could notice if a software client was attempting to impersonate a hardware device"; for servers using verification_uri_complete "it is particularly important to confirm that the device is in the user's possession ... display the code during the authorization flow and ask the user to verify that the same code is currently being displayed on the device"; the code lifetime "should be sufficiently short to limit the usability of a code obtained for phishing." §5.5: a bystander who sees the code can "hijack the session by completing the authorization faster than the user that initiated it." §5.3: the approving browser's signals say nothing about the device's trustworthiness. §5.6: device clients are public clients. [§5.3–§5.6]

    2. How the CLIs do it, and the phishing record

    CLI Protocol Code shown Person enters or confirms Expiry Machine name Token life
    gh RFC 8628 against GitHub 8 chars WDJB-MJHT enters at github.com/login/device 900 s, interval 5 none no expiry; revoked after 1 year unused
    Claude Code auth-code + localhost callback; browser shows a code to paste into the terminal when callback unreachable n/a (reverse direction) pastes browser code into terminal unverified none login expires (warned 3 days out); claude setup-token = 1 year
    Codex auth-code + localhost:1455; opt-in device code (beta) one-time code enters at /codex/device 15 min none unverified
    Vercel RFC 8628 (since 2025-09-12) user_code enters (CLI opens verification_uri_complete; whether the page prefills is unverified) unverified none refresh token (offline_access)
    Fly bespoke "CLI session", no code none approves in browser 15 min poll timeout hostname sent as session name "very short-lived" (duration unverified)
    Stripe (legacy "RAK" flow) bespoke pairing word pairing code confirms in Dashboard unverified hostname or STRIPE_DEVICE_NAME, visible in Dashboard 90 days
    Stripe (new OAuth flow, feature-flagged per machine) RFC 8628 against access.stripe.com user_code (format unverified) enters ("When prompted, enter your verification code") server expires_in, CLI floor 10 min device_name still sent on the gating call access token + refresh token in OS keyring

    gh / GitHub. "The user verification code is 8 characters with a hyphen in the middle" (WDJB-MJHT); expires_in "default is 900 seconds or 15 minutes"; interval 5; slow_down adds 5 s; errors authorization_pending, slow_down, expired_token, unsupported_grant_type, incorrect_client_credentials, incorrect_device_code, access_denied, device_flow_disabled; user-code submissions rate-limited to "50 submissions in an hour per application" [https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps]. gh prints First, copy your one-time code: %s and opens code.VerificationURI, not the complete URI; the person types the code [https://raw.githubusercontent.com/cli/oauth/main/oauth_device.go]. Polling multiplies the interval by 1.2 (1.4 after a slow_down) to survive VM clock drift and aborts after two slow_downs [https://raw.githubusercontent.com/cli/oauth/main/device/device_flow.go]. gh auth login flags --web, --with-token, --hostname, --scopes, --git-protocol, --clipboard ("Copy one-time OAuth device code to clipboard") [https://raw.githubusercontent.com/cli/cli/trunk/pkg/cmd/auth/login/login.go]; minimum scopes repo, read:org, gist [https://raw.githubusercontent.com/cli/cli/trunk/internal/authflow/flow.go]. No machine naming; the grant is per OAuth app. OAuth-app tokens have no expiry but "GitHub will automatically revoke an OAuth token or personal access token when the token hasn't been used in one year" [https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/token-expiration-and-revocation]. What the confirm page shows: the requesting app and requested scopes (Praetorian, below); the page itself could not be fetched unauthenticated (unverified).

    Claude Code. "If your browser shows a login code instead of redirecting back after you sign in, paste it into the terminal at the Paste code here if prompted prompt. This happens when the browser can't reach Claude Code's local callback server, which is common in WSL2, SSH sessions, and containers." Credentials in macOS Keychain, falling back to ~/.claude/.credentials.json mode 0600 (also the Linux storage); "Your login expires in 3 days · run /login to renew" (v2.1.203+); claude setup-token mints "a one-year OAuth token" for CLAUDE_CODE_OAUTH_TOKEN [https://code.claude.com/docs/en/authentication]. Not a device flow: the code travels browser to terminal.

    Codex. Default flow tunnels "the localhost callback Codex uses to return the OAuth token to the CLI". Device code is "(beta)": "In the interactive login UI, choose Sign in with Device Code, or run codex login --device-auth"; "Enable device code login in your ChatGPT security settings (personal account) or ChatGPT workspace permissions (workspace admin)"; the person must "Open the link in your browser, sign in, then enter the one-time code"; credentials in ~/.codex/auth.json or the OS credential store (auto prefers the store) [https://learn.chatgpt.com/docs/auth.md, redirected from developers.openai.com/codex/auth.md]. Source: endpoints {auth}/deviceauth/usercode and {auth}/deviceauth/token, verification page /codex/device, 15-minute cap ("device auth timed out after 15 minutes"), server-supplied interval [https://raw.githubusercontent.com/openai/codex/main/codex-rs/login/src/device_code_auth.rs]. Code format: not validated client-side (unverified).

    Vercel. Changelog 2025-09-12: CLI moved to the "industry-standard OAuth 2.0 Device Flow" (links rfc8628); email login and --github/--gitlab/--bitbucket/--oob stopped working 2026-02-26 [https://vercel.com/changelog/new-vercel-cli-login-flow]. Discovery advertises device_authorization_endpoint: https://api.vercel.com/login/oauth/device-authorization and grant_types_supported of authorization_code, client_credentials, refresh_token, urn:ietf:params:oauth:grant-type:device_code [https://vercel.com/.well-known/openid-configuration]. CLI prints Visit {verification_uri} and enter {user_code}, opens verification_uri_complete, handles slow_down ("Authorization server requests to slow down. Polling every {interval}s") [https://raw.githubusercontent.com/vercel/vercel/main/packages/cli/src/commands/login/future.ts]; client id cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp, scope openid offline_access, acr_values on re-auth [https://raw.githubusercontent.com/vercel/vercel/main/packages/cli/src/util/oauth.ts]. Code format, expiry and the browser page: server-side, unverified.

    Fly. Not RFC 8628. POST /api/v1/cli_sessions with name = the machine hostname (os.Hostname() in internal/command/command.go, carried on the context as state.Hostname), browser opened to auth_url, GET /api/v1/cli_sessions/{id} polled every second, 15-minute timeout ("Login expired, please try again"), PKCE redeem via /cli_sessions/{id}/redeem when the server supports it [https://raw.githubusercontent.com/superfly/flyctl/master/internal/command/auth/webauth/webauth.go, https://raw.githubusercontent.com/superfly/fly-go/main/cli_session.go]. No user code at all. The login token is "a very short-lived token that is automatically created each time you log in"; lifetime not stated [https://fly.io/docs/security/tokens/].

    Stripe. Two flows coexist in v1.50.8.

    Legacy pairing flow (the one the earlier draft described): the CLI "displays a pairing code and opens the Stripe Dashboard, where you confirm the code" [https://docs.stripe.com/cli/login]. Source strings: Your pairing code is: %s, This pairing code verifies your authentication with Stripe., Press Enter to open the browser or visit %s (^C to quit), Waiting for confirmation..., Please note: this key will expire after 90 days, at which point you'll need to re-authenticate. [https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/client_login.go]. Pairing code is word-based, "e.g. excels-champ-wins-quaint" [https://raw.githubusercontent.com/stripe/stripe-cli/master/rpc/login.proto]; the docs' --non-interactive example shows "browser_url": "https://dashboard.stripe.com/stripecli/confirm?..." and "verification_code": "ABCD-EFGH" [https://docs.stripe.com/cli/login], a contradiction between docs and source. The browser URL and poll URL are server-supplied via POST /stripecli/auth with device_name [https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/links.go]; the confirm_auth?t=<secret> shape seen earlier is a test fixture [https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/client_login_test.go], not verified against production. Device name defaults to os.Hostname() [https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/config/config.go], overridable with STRIPE_DEVICE_NAME, "the device name for the CLI, visible in the Dashboard" [https://docs.stripe.com/stripe-cli/keys]. What the Dashboard confirm page shows beyond the code: unverified (needs a login).

    New OAuth device-code flow (added 2026-08-10, "Implement OAuth login flow (#1880)"; in v1.50.8): GetLinks sends machine_uuid "so it can gate individual machines into the OAuth device-code flow via feature flag ... instead of proceeding with the legacy RAK flow" [links.go]. When gated in, the CLI runs RFC 8628 against https://access.stripe.com/stripecli/oauth2/device/authorization and /token (grant_type=urn:ietf:params:oauth:grant-type:device_code, client id oacli_V18aOD6v0hs9CU, scope stripecli), prints To authorize, visit %s, then When prompted, enter your verification code: and the user_code; the person types it. Polling honours the server interval with a 5 s floor, doubles the wait on slow_down, and gives up at max(expires_in, 10 min) ("device code expired; please run 'stripe login' again"). It stores the access token in the profile and the refresh token in the OS keyring, refreshing with grant_type=refresh_token ("session expired; run 'stripe login' to re-authenticate" when the refresh fails) [https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/oauth_device.go, https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/login.go, https://raw.githubusercontent.com/stripe/stripe-cli/master/pkg/login/oauth_refresh.go]. The docs' "stores your credentials in your operating system's secure credential store (when available) and refreshes the session automatically", stripe login list, stripe switch context, stripe reauth describe this flow [https://docs.stripe.com/cli/login]. Token lifetimes are server-set and unverified. Net: Stripe is moving away from confirm-the-code toward the plain RFC flow; the precedent for confirm-plus-machine-name is its legacy path, and Fly's session flow.

    Device-code phishing, 2024–2026.

    • Microsoft, 2025-02-13: Storm-2372 "generates a legitimate device code request and tricks the target into entering it into a legitimate sign-in page"; lures were Teams meeting invites after rapport on WhatsApp/Signal; mitigations "Only allow device code flow where necessary. Microsoft recommends blocking device code flow wherever possible", Conditional Access, phishing-resistant MFA, and "Sign-in prompts should clearly identify the application being authenticated to" [https://www.microsoft.com/en-us/security/blog/2025/02/13/storm-2372-conducts-device-code-phishing-campaign/].
    • Volexity, 2025-02-13: UTA0304, UTA0307, CozyLarch (APT29); codes "only valid for 15 minutes", victims sent to login.microsoftonline.com/common/oauth2/deviceauth; effective because "There is no 'malicious' link or attachment. The only link is to the provider's infrastructure". UTA0307 already used an interstitial page: "Having an interstitial page that automatically generates new codes means UTA0307 does not have to worry about their phishing content expiring" [https://www.volexity.com/blog/2025/02/13/multiple-russian-threat-actors-targeting-microsoft-device-code-authentication/].
    • Praetorian, 2025-06-12, GitHub: attacker's own OAuth app (logo customisable), victim enters the code at github.com/login/device, page shows the app and scopes, codes expire in "15 minutes"; "convinced targets, typically developers, to complete the device flow >90% of the time when calling on the phone" [https://www.praetorian.com/blog/introducing-github-device-code-phishing/].
    • Sekoia, 2026-03-30, EvilTokens PhaaS: the phishing page displays a user code the victim copies, then a "Continue to Microsoft" button to the real device-login page; the backend requests a fresh code per page load so the 15-minute window never lapses (the same trick Volexity saw in 2025); over 1,000 pages by 2026-03-23 [https://www.sekoia.com/blog/new-widespread-eviltokens-kit-device-code-phishing-as-a-service-part-1].
    • Okta, 2026-05-11: "Only allow the use of the device code flow by exception" [https://www.okta.com/blog/threat-intelligence/device-code-phishing--it-s-phishing-with-dynamite/].
    • Microsoft Entra (page updated 2026-07-01): "Starting July 1, 2026, all new Microsoft Entra tenants block device code flow as part of security defaults" [https://learn.microsoft.com/en-us/entra/fundamentals/security-defaults].
    • Secondary (vendor blog, not independently verified): Push Security, post dated 2026-04-04 with an update noted 2026-05-15, reports a 37.5x rise in device-code phishing pages seen by its team in 2026 (up from 15x at the start of March) [https://pushsecurity.com/blog/device-code-phishing].

    What the record says for the design: every incident has the attacker start the flow and the victim type the attacker's code on the provider's real page. A confirm-only page removes the "type this code" lure but not the "click this link" lure (EvilTokens and UTA0307 already relay links and refresh codes), so the page must do what RFC §5.4 asks: state that a machine is being authorised, name the machine, show the code for comparison, and expire fast. Patchy's confirm page is also scoped to one company and one capability (publish), which bounds the blast radius in a way Microsoft 365 and GitHub grants do not.

    3. Clerk's machine auth, and whether it changes the decision

    Token types. @clerk/backend 3.17.0 classifies machine tokens by prefix: ak_ API key, mt_ M2M token, oat_ OAuth access token, or JWT with typ: at+jwt / application/at+jwt (OAuth) or sub: mch_… (M2M) [https://raw.githubusercontent.com/clerk/javascript/main/packages/backend/src/tokens/machine.ts]. authenticateRequest({ acceptsToken }) accepts 'api_key' | 'oauth_token' | 'session_token' | 'm2m_token', an array, or 'any'; default 'session_token' (options.acceptsToken ?? TokenType.SessionToken); the result carries tokenType and isAuthenticated; jwtKey (PEM from Dashboard) is "used to verify the session token in a networkless manner" [https://clerk.com/docs/reference/backend/authenticate-request, https://raw.githubusercontent.com/clerk/javascript/main/packages/backend/src/tokens/request.ts]. Opaque machine tokens are verified by Backend API calls through client.apiKeys.verify, client.m2m.verify and client.idPOAuthAccessToken.verify [https://raw.githubusercontent.com/clerk/javascript/main/packages/backend/src/tokens/verify.ts], which hit POST /api_keys/verify, POST /m2m_tokens/verify and POST /oauth_applications/access_tokens/verify [packages/backend/src/api/endpoints/APIKeysApi.ts, M2MTokenApi.ts, IdPOAuthAccessTokenApi.ts; https://clerk.com/docs/guides/configure/auth-strategies/oauth/verify-oauth-tokens]. Token-format trade-off in Clerk's words: JWTs "can be verified locally using your instance's public key, without making a network request"; opaque tokens "must be verified by making a request to Clerk's servers"; "Once issued, a JWT remains valid until it expires" [https://raw.githubusercontent.com/clerk/clerk-docs/main/docs/guides/development/machine-auth/token-formats.mdx].

    API keys (GA 2026-04-17 [https://clerk.com/changelog/2026-04-17-api-keys-ga]). clerkClient.apiKeys.create({ name, subject: 'user_…' | 'org_…', secondsUntilExpiration?, scopes?, claims? }); "By default, API keys never expire"; the secret "is only available in the initial response from create()"; verify() "will throw an error" if invalid, revoked or expired; revoke({ revocationReason }) is immediate; an API Keys tab appears in <UserProfile /> / <OrganizationProfile /> [https://clerk.com/docs/guides/development/machine-auth/api-keys]. Pricing: 1,000 creations and 100,000 verifications included per month, then $0.001 per creation and $0.00001 per verification [https://clerk.com/pricing]. Always opaque, so every verification is a network call to Clerk.

    M2M tokens (GA 2025-10-14 [https://clerk.com/changelog/2025-10-14-m2m-ga]; JWT format since 2026-02-24). Subject is a mch_ machine with its own secret key, not a user; createToken({ secondsUntilExpiration?, tokenFormat?: 'opaque' | 'jwt' }), "By default, the token will not expire"; "JWT tokens are not stored by Clerk and therefore cannot be revoked" [https://clerk.com/docs/guides/development/machine-auth/m2m-tokens]. Pricing: 2,500 creations and 100,000 verifications included per month, then $0.001 / $0.00001 [https://clerk.com/pricing].

    OAuth access tokens (Clerk as provider). Discovery at <FAPI>/.well-known/oauth-authorization-server advertises grant_types_supported: ["authorization_code", "refresh_token"], code_challenge_methods_supported: ["S256"] (docs example, and confirmed live on well-hagfish-71.clerk.accounts.dev on 2026-09-02, which has no device_authorization_endpoint); public clients via a Dashboard toggle; "OAuth access tokens expire after 1 day", "Refresh tokens never expire", "Authorization codes expire after 10 minutes"; JWT by default (since 2026-01-08 [https://clerk.com/changelog/2026-01-08-jwt-oauth-access-tokens]) or opaque for instant revocation; consent screen on by default [https://raw.githubusercontent.com/clerk/clerk-docs/main/docs/guides/configure/auth-strategies/oauth/how-clerk-implements-oauth.mdx]. Clerk's CLI guidance is auth-code + PKCE on a 127.0.0.1 loopback port, refreshing when "within 30s of expiry", and lists the device grant under "What this post doesn't cover": "RFC 8628. Best for CI, headless servers, and environments where the CLI can't open a browser. Outside the scope of this post." [https://clerk.com/blog/adding-clerk-auth-to-your-cli]; its reference repo says "Device Authorization Grant (RFC 8628) is not implemented. The localhost-callback flow needs an open port, which doesn't work for CI, containers, or SSH sessions. If you need that, open an issue" [https://github.com/clerk/cli-auth-example].

    Device grant, gated. Clerk's error catalogue gained feature_requires_device_authorization_grant ("The OAuth 2.0 device authorization grant is not enabled for this instance. Please contact support to enable this feature", 422, FAPI and BAPI) and feature_requires_device_verification_url ("This feature requires a reachable device verification page. Configure a device verification URL or enable the Account Portal", 422, FAPI) in commit 49283e33 on 2026-08-27, and oauth_device_code_expired ("The user code has expired. Start the device authorization flow again.", 400, FAPI, file oauth2_idp.go) in commit 33a207f0 on 2026-08-31; both commits are "chore: sync docs from clerk/clerk@…" touching only data/api_errors.json [https://github.com/clerk/clerk-docs/blob/main/data/api_errors.json]. GitHub code search on 2026-09-02: device_authorization appears in clerk/clerk-docs only in that file, device_code has zero hits in clerk/javascript, and clerk.com/changelog/changelog.md has no device-grant entry. Treat it as an unreleased, support-gated feature.

    Does any of it change the decision? No. Tested against the five reasons:

    • Local verification: only a JWT-format OAuth token gives it. API keys and opaque OAuth tokens are a Clerk round-trip per request.
    • No Clerk on the publish path: a JWT OAuth token lasts 1 day, so every publish after that needs a refresh against Clerk; API keys need Clerk on every verify.
    • Idle expiry (30 days since last use): no Clerk machine token has it; the only knob is fixed secondsUntilExpiration.
    • Revoke-on-deactivate: possible for API keys and opaque OAuth tokens through Clerk's API, impossible for JWT tokens. Either way the revocation state lives in Clerk, not next to Patchy's membership row.
    • Every version naming the token that published it: API keys carry a name, but the list of a user's machines would live in Clerk's <UserProfile />, not in Patchy's data.
    • Device grant: exists behind a gate with no public contract; the loopback flow Clerk does support is the one Codex and Claude Code document as failing in SSH, WSL2 and containers.

    A Patchy-minted, Patchy-verified opaque token, listed and revoked in Patchy's own tables, is the only option that satisfies all five. Clerk's role stays exactly where the door already puts it: the browser session that authorises the confirm page.

    What to take into the protocol design

    • Code: 8 chars from BCDFGHJKLMNPQRSTVWXZ, shown as XXXX-XXXX; compare case-insensitively with punctuation stripped (RFC §6.1's worked example; the RFC only formally RECOMMENDS avoiding confusable characters). Because nobody types it, its job is visual comparison; the URL id and the CLI's polling secret carry the entropy (RFC §5.2), 128 bits or more each.
    • Expiry: 15 minutes is the common value (GitHub 900 s, Codex, Fly, Volexity's observation; Stripe's new flow floors at 10 min). RFC §5.4 argues for the shortest usable window; 10 minutes is defensible given the browser is already signed in.
    • Polling: interval 5 s, slow_down adds 5 s, authorization_pending / expired_token / access_denied as the poll states (RFC §3.5); return these as --json shapes per ADR-0004.
    • Rate limits: cap confirm attempts per session and per user (GitHub uses 50/hour/app); cap polling per device code.
    • Confirm page: say "Allow to publish patches as at ?", show the code, and require the machine name on first login (Stripe: hostname default; Fly: hostname as session name).
    • Token: patchy login stores Patchy's token as gh/Stripe/Codex do, in the OS keyring with a 0600 file fallback (Claude Code documents that fallback; Stripe warns on insecure storage and Codex's auto mode falls back to auth.json).

    Open questions

    • Confirm vs type: the §3.3.1 form still needs the person to compare; a kit can relay the link. Do we want a "type the code" fallback for when the link is opened on a different device (QR, §3.3.1), or is the link-only path enough for launch? Note Stripe's newest flow went the other way (enter, not confirm).
    • Should confirming require a fresh Clerk sign-in (step-up, as Vercel's acr_values re-auth does) rather than any live session?
    • Stripe's docs (ABCD-EFGH, /stripecli/confirm?...) and source (word codes, /stripecli/confirm_auth?t= in a test) disagree; which the Dashboard actually renders is unverified.
    • Clerk's gated device grant: is it worth asking support what it issues, in case a Clerk-issued token is ever wanted for a non-publish surface? Not needed for this design.
    • Vercel and Stripe confirm-page contents, Fly's login-token lifetime, Stripe's new-flow token lifetimes, and Codex's code format are unverified (behind logins or server-side).

    Verification

    Checked on 2026-09-02 against the cited primary sources (RFC 8628 text; raw source from cli/oauth, cli/cli, stripe/stripe-cli, superfly/flyctl, superfly/fly-go, openai/codex, vercel/vercel, clerk/javascript, clerk/clerk-docs, clerk/cli-auth-example; docs pages at docs.github.com, docs.stripe.com, fly.io, vercel.com, code.claude.com, learn.chatgpt.com, clerk.com; the Microsoft, Volexity, Praetorian, Sekoia, Okta, Push Security posts and the Entra security-defaults page; a live Clerk dev-instance discovery document; GitHub commit and release metadata via the API).

    Confirmed unchanged: RFC §3.2, §3.3.1, §3.5, §5.1, §5.2, §5.4 quotations; all five phishing incidents and the Entra 2026-07-01 default; Clerk's advertised grants, the reference repo's "not implemented", the gated device-grant error codes and their commit dates; Clerk API-key, M2M and OAuth token lifetimes, revocation limits and pricing; @clerk/backend 3.17.0 prefixes, acceptsToken default and jwtKey; GitHub's device-flow parameters and one-year unused-token revocation; Claude Code, Codex, Vercel and Fly flow details; all version numbers.

    Changed: (1) Stripe: the pairing-code-confirm flow is now the legacy path; v1.50.8 ships a feature-flagged RFC 8628 flow where the person types the code, with refresh tokens in the keyring, so Stripe is no longer a clean confirm-not-enter precedent; the confirm_auth?t= URL was a test fixture and the docs show /stripecli/confirm?.... (2) RFC §6.1 wording: the base-20 alphabet is the RFC's worked example ("one way"), not a RECOMMENDED profile. (3) Clerk verify paths: the SDK methods are apiKeys.verify / m2m.verify / idPOAuthAccessToken.verify and the REST paths are /api_keys/verify, /m2m_tokens/verify, /oauth_applications/access_tokens/verify. (4) Small fixes: gh prints "First, copy your one-time code"; Codex device login is labelled beta; Vercel's discovery also lists client_credentials; Volexity documented the fresh-code interstitial a year before EvilTokens; Push Security's 37.5x figure carries a 2026-05-15 update; Clerk's blog explicitly scopes the device grant out; M2M verifications are also metered.

    Still unverifiable: contents of the GitHub, Vercel and Stripe confirm pages (behind login); Fly's login-token lifetime and Stripe's new-flow access/refresh token lifetimes (server-side); Codex's and Stripe-OAuth's user-code format; whether Vercel's verification_uri_complete page prefills the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:research

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions