Skip to content

feat: sign in to ChatGPT from another device - #42

Merged
fylorn merged 2 commits into
mainfrom
feat/chatgpt-device-code
Sep 18, 2026
Merged

fylorn merged 2 commits into
mainfrom
feat/chatgpt-device-code

Conversation

@fylorn

@fylorn fylorn commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Adds the device-code half of ChatGPT sign-in, so the user can pick where to authorise: this computer's browser, or a code typed on a device that is already signed in.

What changed

  • POST /chatgpt/login takes mode: browser (default, unchanged) or device. The device reply carries user_code + verification_url and no authorize_url (now optional).
  • Both paths share one exchange_and_save, so a device login produces exactly the same provider, credentials and account header as a browser login — and the same login_finished event.
  • Polling treats 403/404 as "not approved yet" and stops at the same 15-minute deadline as the browser flow; the interval is the server's, with a 3-second floor so a 0 cannot turn into a busy loop.
  • An account the server has not enabled for device login gets a 409 that names the way out: sign in on this computer instead.
  • GET /providers/{name}/chatgpt/usage now records what it learns into the in-memory quota, so the upstreams page has something to show after a cold start instead of waiting for the account's first request.

Protocol

From OpenAI's Codex (codex-rs/login/src/device_code_auth.rs), Apache-2.0 — read for the protocol only. The PKCE pair is the server's on this path: it hands back the verifier with the authorization code, and the exchange reports {issuer}/deviceauth/callback as the redirect.

Tests

Three new tests against the fake OpenAI: a device login that is approved only on the second ask (asserting the code, the verification URL, the polling body, the server's verifier in the token exchange, and the config it writes), an account without device login, and an unknown mode. usage_shows_the_limits_without_personal_details now also asserts /quota is empty before and filled after.

All gates pass locally: fmt, clippy -D warnings, cargo test --workspace, ./scripts/smoke.sh (48 passed, 0 failed).

🤖 Generated with Claude Code

Some machines cannot open the browser that OAuth needs: a headless box, a
remote shell, a work laptop where the account lives on a phone. The device
flow covers those — core asks OpenAI for a one-time code, the user types it
on whatever device is already signed in, and core waits for the approval.

`POST /chatgpt/login` takes `mode`: `browser` (the default, unchanged) or
`device`, which answers with `user_code` and `verification_url` instead of
`authorize_url`. Both paths end in the same place, so a device login writes
the same provider, the same credentials and the same account header as a
browser login; `authorize_url` is now optional in the reply.

Not every account can use it. When the server has not enabled the flow the
code request 404s, and we say so with the one thing the user can do about
it: sign in on this computer instead.

Asking for usage now records the quota too. It lives only in memory, so
after a cold start the upstreams page had nothing to show until the account
saw its first request — one lazy fetch when the page opens now fills it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 21fab4c into main Sep 18, 2026
1 check passed
@fylorn
fylorn deleted the feat/chatgpt-device-code branch September 18, 2026 15:43
@fylorn fylorn mentioned this pull request Sep 18, 2026
fylorn added a commit that referenced this pull request Sep 18, 2026
Sign in to ChatGPT from another device (#42): pick between this computer's
browser and a code typed on a device that is already signed in. Asking for
usage now also fills the in-memory quota, so the upstreams page has
something to show after a cold start.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant