[login] revoke existing auth before starting login - #27674
Merged
Conversation
cooper-oai
marked this pull request as ready for review
June 11, 2026 21:03
Contributor
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 462c54e418
ℹ️ 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".
celia-oai
self-requested a review
June 11, 2026 22:35
celia-oai
reviewed
Jun 12, 2026
cooper-oai
force-pushed
the
cooper/revoke-before-login
branch
from
June 12, 2026 18:50
3efaf9c to
21c4565
Compare
celia-oai
approved these changes
Jun 12, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
codex loginpreviously persisted newly issued OAuth credentials and only then attempted to revoke the superseded refresh token. The old credential must be revoked before a replacement browser or device-code flow starts, and successful login must not perform any post-login revocation attempt.What changed
autostorage fallback semantics when keyring deletion fails by clearing the fallback auth file.If replacement login is canceled or fails, the previous local credentials have already been cleared. Remote revocation remains best effort, matching explicit logout behavior.
Validation
Process-level before/after reproduction
I compiled the real
codexCLI from the pre-fix parent (14df0e8833) and from the PR implementation (25c002f23b; the login behavior is unchanged at the current head), then ran the same device-code flow against a local HTTP mock OAuth authority.Each run:
Used a fresh temporary
CODEX_HOMEconfigured withcli_auth_credentials_store = "file".Seeded that temporary home with managed ChatGPT auth containing
old-accessandold-refreshtokens.Pointed
CODEX_REVOKE_TOKEN_URL_OVERRIDEat the mock/oauth/revokeendpoint.Ran the compiled CLI as:
Recorded every request received by the mock authority. The mock marked
new-accessvalid when/oauth/tokenissued it and invalidated it if/oauth/revokearrived afterward, reproducing the observed session-invalidating failure mode. After login exited, the harness also verified the persisted refresh token and probed a protected endpoint withnew-access.new-accessprobeusercode → device token → OAuth token → revoke(old-refresh)0;new-refreshpersisted401revoke(old-refresh) → usercode → device token → OAuth token0;new-refreshpersisted200The PR run therefore issued exactly one revocation request, before any request that initiated the replacement login, and issued no revocation after token exchange.
Regression coverage
codex-rs/cli/tests/login.rs::device_login_revokes_existing_auth_before_requesting_new_tokensruns the real first-partycodexbinary against awiremockOAuth server with an isolated temporaryCODEX_HOME. It asserts:/oauth/revoke,/api/accounts/deviceauth/usercode,/api/accounts/deviceauth/token, then/oauth/token;old-refreshwith therefresh_tokenhint;new-refresh.Local validation:
just test -p codex-login— 130 passedjust test -p codex-cli— 280 passed, including the new process-level regression testjust bazel-lock-check