Repository navigation
feat(oauth): code-display login mode for hosts with no reachable localhost (carry #6239) - #7170
Conversation
…lhost (carry #6239) Anthropic's code-display redirect lets a login complete from a container or remote host: the user approves in any browser and pastes the displayed code#state, and no callback port is bound. POST /api/oauth/login accepts mode:"code" and returns a flowId and expiresAt; POST /api/oauth/login/code answers with the token-exchange outcome for a code flow. Login flow state is keyed by flow id so concurrent code logins stay separate, with a 10-minute paste window and a 64-row per-provider cap. The CLI spelling is `ocx login <provider> --headless`. Carried onto current dev from #6239 (head 0192c2e). Changes from the source: code mode is wired through the shared anthropicOAuthDefinition so anthropic and anthropic2 both support it; the CLI flag is --headless because --code carries a secret value elsewhere in the CLI and its operand is scrubbed from stderr; a code flow is single-use once a paste reaches the token exchange. Co-authored-by: Vadym O. <[email protected]>
…eep flow ids scoped Independent review fixes for the carried code-display login: - the paste route reports the account this flow persisted, and a flow cleared during its exchange answers no_pending_login instead of success - a flowId is honoured only for a code flow of the same provider, in both the paste route and getLoginStatus, so only single-use code flows hold a waiting request - a paste that races the start is refused instead of spending the flow - ocx login --headless prints only fixed text on failure, never the provider error body Co-authored-by: Vadym O. <[email protected]>
Matching the returned refresh token against the account set missed the row when a concurrent login for the same account rotated the token before the earlier flow settled, so that flow answered without its account. saveCredential now returns the write receipt it already produced, and runLogin reports the persisted account id to startLoginFlow. Co-authored-by: Vadym O. <[email protected]>
saveAccountCredential resolves false when the account vanished before the queued write, and runLogin reports the persisted account only after a real write. Test stubs of saveCredential now return the write receipt. Co-authored-by: Vadym O. <[email protected]>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 23
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Deterministic PR hygiene checks passed. |
# Conflicts: # structure/INDEX.md
# Conflicts: # structure/INDEX.md
|
Maintainer integration into
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93c1aa3b45
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { url: authUrl, instructions, deviceCode, expiresAt } = await startLoginFlow(provider, { | ||
| forceLogin: body.addAccount === true || reauth, | ||
| ...(accountId ? { reauthAccountId: accountId } : {}), | ||
| ...(codeMode ? { codeMode: true } : {}), |
There was a problem hiding this comment.
Suppress browser launch in code mode
When POST /api/oauth/login requests mode: "code" without explicitly setting openBrowser: false, the new branch still falls through to the existing launcher, and shouldOpenBrowserForLogin(undefined, config) defaults to true. This violates the headless mode contract and unexpectedly opens the authorization page on the proxy host; skip the browser-launch block whenever codeMode is true.
Useful? React with 👍 / 👎.
| if (error instanceof AnthropicTokenError) { | ||
| return error.httpStatus !== undefined && error.httpStatus >= 500 | ||
| ? "provider_unreachable" | ||
| : "invalid_or_expired_code"; |
There was a problem hiding this comment.
Report pre-connection DNS failures as unreachable
When a direct Anthropic token request fails DNS resolution, postJson deliberately wraps it in AnthropicTokenError with requestNotSent === true and no HTTP status. This branch classifies that network failure as invalid_or_expired_code before the generic network checks can run, so headless callers receive incorrect remediation; classify requestNotSent as provider_unreachable.
Useful? React with 👍 / 👎.
| return jsonResponse({ | ||
| url: authUrl, | ||
| instructions, | ||
| deviceCode, | ||
| browserLaunch, | ||
| ...(codeMode ? { mode: "code", flowId, expiresAt } : {}), |
There was a problem hiding this comment.
Honor the returned flow ID when reading OAuth status
The code-mode start response now returns a flowId, but GET /api/oauth/status?provider=anthropic&flowId=<id> still calls getLoginStatus without passing that query parameter. With two concurrent code-display logins, status for flow A therefore reports whichever flow is newest (usually B), despite getLoginStatus supporting an explicit ID; pass the validated flowId through for non-Kiro OAuth flows.
Useful? React with 👍 / 👎.
Summary
Carries #6239 by @vadymhimself (source head
0192c2e4b) onto currentdev. That branch was 676 commits behind and conflicted in the Anthropic OAuth, login-registry, and CLI files.Problem. Anthropic login always redirects to
http://localhost:54545/callback. When ocx runs somewhere the operator's browser can't reach (a container, a remote server, a hosted gateway), approval lands on a dead localhost page.Change. Anthropic's code-display redirect (
https://platform.claude.com/oauth/code/callback, the same OAuth client Claude Code uses) shows acode#statestring that the user pastes back. No callback port is bound and no browser is launched.POST /api/oauth/loginaccepts an optionalmode. Omitting it, or sending"callback", keeps today's flow and response shape."code"returns{url, mode, flowId, expiresAt}. Providers without a code-display redirect are refused withcode_mode_unsupportedand never fall back to localhost.POST /api/oauth/login/codewith thatflowIdanswers with the outcome of the token exchange:{ok:true, account}or{ok:false, error}, whereerrorisstate_mismatch,invalid_or_expired_code,no_pending_login,provider_unreachableormalformed_input. Requests without aflowIdkeep the existing accept-only contract.ocx login anthropic --headlessprints the URL and reads the code back. Codex spellings are refused with a pointer toocx account login codex --device. Other unsupported providers exit with the list of supported ones.Differences from the source branch.
anthropicOAuthDefinitionadded ondevsince the PR was opened, soanthropicandanthropic2both support it. The anthropic2 local-import refusal and the Claude-import identity binding are unchanged.--headlessinstead of--code. Ondev,--code <value>carries secret authorization material (ocx account login --code), and the argument redactor scrubs the word after it from stderr. That turnedocx login --code codexinto<redacted> has no code-display login.saveCredentialnow returns the receipt it already produced).no_pending_logininstead of success.flowIdis honoured only for a code flow of the same provider, in the paste route and in status.--headlesslogin prints only fixed text, never the provider error body.Docs:
structure/providers/oauth-code-display-login.md(new owner doc, linked fromgui-and-management-api.md),docs-siteCLI reference, the providers guide, and the management API reference.Co-authored-by: Vadym O. [email protected]
Verification
On head
252db6821, branch is on the currentdevtip (0 behind), sandboxedOPENCODEX_HOME/CODEX_HOME:bun run test:changedon2474604a0ran 1767 files: 38455 pass, 107 skip, 23 fail, 4 errors, all in areas this change does not touch (service install state, live audio, desktop settings, Codex/Grok toggles, headless parity, sibling-home client sync). Run alone, each of those files passes on this branch excepttests/cli/sibling-home-client-sync.test.ts("a secondary ensure parent preserves shared Grok, Codex and Claude agent bytes", 30s timeout). That test fails the same way on a clean checkout of the merge base7640a942b, wheretests/cli/cli-headless-parity.test.tsalso fails 2 tests. The twotests/clifailures above are those same two files. The last commit (252db6821, reauth write reporting plus test stub return types) was re-verified with the oauth, CLI provider and Kiro runs listed above.New tests in
tests/oauth/oauth-code-login.test.tscover each review fix: single-use, own-account reply, concurrent same-account logins, clear during exchange, a paste racing the start, provider and callback flow-id scoping, and no provider body on CLI stderr. Each new case was confirmed to fail or hang with its source fix stashed. The fullbun run testwas not run locally because of contention across concurrent worktrees; full cross-platform CI was dispatched on the carry branch: https://github.com/lidge-jun/opencodex/actions/runs/38717906093 (queued at the time of writing).Checklist