Repository navigation
feat: sign in to ChatGPT from another device - #42
Merged
Merged
Conversation
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>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
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>
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.
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/logintakesmode:browser(default, unchanged) ordevice. The device reply carriesuser_code+verification_urland noauthorize_url(now optional).exchange_and_save, so a device login produces exactly the same provider, credentials and account header as a browser login — and the samelogin_finishedevent.0cannot turn into a busy loop.GET /providers/{name}/chatgpt/usagenow 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/callbackas 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_detailsnow also asserts/quotais 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