Repository navigation
Switch OpenAI and xAI login to device-code OAuth - #40
Merged
Merged
Conversation
- Replace the loopback callback server in `performOpenAIOAuthFlow` with Codex device-code request, poll, and token exchange. - Replace the loopback callback server in `performXaiOAuthFlow` with RFC 8628 device-code request and token poll. - Prompt for the one-time code in `Setup` before opening the verification URL, and log auth failures from `run()`. - Document that ChatGPT and Grok sign-in use device code plus URL and work over SSH.
- Add `test/infra/auth/openai.test.ts` for usercode, poll, token exchange, pending retries, and `onDeviceCode`. - Rewrite `test/infra/auth/xai.test.ts` for device-code request, poll, pending/slow_down retries, and denial errors. - Cover the setup device-login prompt and error logging in `test/cli/setup.test.ts`.
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. |
- Set package version to 0.3.1 so publish runs for the device-code OAuth release. - Sync the README version badge with `package.json`.
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.
What's New
Device-Code OAuth
/api/accounts/deviceauth/usercodeand/token) instead of a loopback callback on port 1455, then exchanges the authorization code atauth.openai.com/oauth/tokenwith redirecthttps://auth.openai.com/deviceauth/callback./oauth2/device/code, then/oauth2/tokenwithurn:ietf:params:oauth:grant-type:device_code) instead of a loopback PKCE callback, retryingauthorization_pendingandslow_down.Setup CLI
Setupprints the one-time code, waits for confirm, then opens the verification URL and logs "Waiting for authentication...". Auth failures from any method are logged inrun()instead of only afterfinalizeSetup.Documentation
Device-Code Login Flow
flowchart TB A["Setup: ChatGPT or Grok OAuth"] --> B["Request device code"] B --> C{"Usercode OK?"} C -->|404 OpenAI| D["Tell user to enable Codex device auth"] C -->|OK| E["Show one-time code"] E --> F["Confirm to open verification URL"] F -->|Cancel| G["Setup cancelled"] F -->|Enter| H["Open browser"] H --> I["Poll token endpoint"] I --> J{"Poll result"} J -->|pending / slow_down| I J -->|complete| K["Store tokens and finish setup"] J -->|denied / expired / timeout| L["Log error and fail"]Changed Files
src/infra/auth/openai.tssrc/infra/auth/xai.tssrc/cli/setup.tsREADME.mdtest/infra/auth/openai.test.tstest/infra/auth/xai.test.tstest/cli/setup.test.tsAdditional for Run Locally
OpenAI device-code authorization
Testing & Feedback
Review the OpenAI device-code request, poll, token exchange, pending retries, and
onDeviceCodecoverage intest/infra/auth/openai.test.ts. Review the xAI device-code request, poll retries (authorization_pending,slow_down),access_denied,expired_token, andonDeviceCodecoverage intest/infra/auth/xai.test.ts. Review the setup prompt, waiting log, and error logging on a failed xAI device login intest/cli/setup.test.ts.If you find any bugs or have recommendations for improvements, please open an issue and assign it to me.