Skip to content

[codex] Revoke ChatGPT tokens on logout#17825

Merged
sashank-oai merged 7 commits intomainfrom
codex/revoke-tokens-on-logout
Apr 17, 2026
Merged

[codex] Revoke ChatGPT tokens on logout#17825
sashank-oai merged 7 commits intomainfrom
codex/revoke-tokens-on-logout

Conversation

@sashank-oai
Copy link
Copy Markdown
Contributor

@sashank-oai sashank-oai commented Apr 14, 2026

Summary

This changes Codex logout so managed ChatGPT auth is revoked against AuthAPI before local auth state is removed. CLI logout, TUI /logout, and the app-server account logout path now use the token-revoking logout flow instead of only deleting auth.json / credential store state.

Root Cause

Logout previously cleared only local auth storage. That removed Codex's local credentials but did not ask the backend to invalidate the refresh/access token state associated with a managed ChatGPT login.

Behavior

For managed ChatGPT auth, logout sends the stored refresh token to https://auth.openai.com/oauth/revoke with token_type_hint: refresh_token and the Codex OAuth client id, then deletes all local auth stores after revocation succeeds. If only an access token is available, it falls back to revoking that access token. API key auth and externally supplied chatgptAuthTokens are still only cleared locally because Codex does not own a refresh token for those modes.

Revocation failures are fail-closed: if Codex cannot load stored auth or the backend revoke call fails, logout returns an error and leaves local auth in place so the user can retry instead of silently clearing local state while backend tokens remain valid.

Validation

ran local version of codex-cli with staging overrides/harness for auth

ran codex login then codex logout:

saw auth.json clear and backend revocation endpoints were called

POST /oauth/revoke
status: 200

revoking access token
should clear auth session
clearing auth session due to token revocation
successfully revoked session and access token
CANONICAL-API-LINE Response: status='200' method='POST' path='/oauth/revoke

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@sashank-oai sashank-oai marked this pull request as ready for review April 14, 2026 19:34
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

if let Err(e) = codex_login::logout(
&self.config.codex_home,
self.config.cli_auth_credentials_store_mode,
) {

P1 Badge Route TUI /logout through token-revoking logout

The TUI logout command still calls codex_login::logout, which only clears local storage. Users logging out via /logout won't hit the new revoke flow, so managed ChatGPT refresh tokens remain valid server-side. This leaves logout behavior inconsistent across surfaces and bypasses the security intent of this change.

ℹ️ 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".

Comment thread codex-rs/login/src/auth/revoke.rs Outdated
Comment thread codex-rs/login/src/auth/revoke.rs Outdated
Comment thread codex-rs/login/src/auth/manager.rs Outdated
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9882aa844b

ℹ️ 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".

Comment thread codex-rs/login/src/auth/manager.rs Outdated
@sashank-oai
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 15, 2026
@sashank-oai sashank-oai force-pushed the codex/revoke-tokens-on-logout branch from 0beb9dd to c789eb3 Compare April 15, 2026 18:17
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7520b3625c

ℹ️ 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".

Comment thread codex-rs/login/src/auth/revoke.rs
@sashank-oai sashank-oai requested a review from cooper-oai April 15, 2026 21:44
sashank-oai and others added 6 commits April 16, 2026 13:52
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Continue deleting local auth state even when the OAuth revoke request fails.

Co-authored-by: Codex <noreply@openai.com>
Increase the command timeout for request-permissions shell events so CI does not time out while waiting for approval and sandbox setup.

Co-authored-by: Codex <noreply@openai.com>
@sashank-oai sashank-oai force-pushed the codex/revoke-tokens-on-logout branch from d02611f to be4de2f Compare April 16, 2026 20:55
let codex_home = self.config.codex_home.clone();
let auth_credentials_store_mode = self.config.cli_auth_credentials_store_mode;
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this to call the app server API for logging out rather than calling the local version. Otherwise this won't work for scenarios where the TUI is connected to a remote host.

This was an existing bug (that I wasn't aware of). Now that we know about it, we should probably fix it here. If you decide not to fix it in this PR, let me know and I can do a follow-up fix.

@@ -0,0 +1,203 @@
use serde::Serialize;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Add header comment explaining what this module does.

Comment thread codex-rs/login/src/auth/manager.rs Outdated
codex_home: &Path,
auth_credentials_store_mode: AuthCredentialsStoreMode,
) -> std::io::Result<bool> {
let storage = create_auth_storage(codex_home.to_path_buf(), auth_credentials_store_mode);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we reloading the auth information from disk here rather than using the AuthManager? It is meant to be the source of truth for the current auth and any tokens associated with it. By going around the AuthManager's back and loading the auth information directly from disk, you're breaking the internal contract.

Copy link
Copy Markdown
Collaborator

@etraut-openai etraut-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@sashank-oai sashank-oai merged commit 22f7ef1 into main Apr 17, 2026
35 of 36 checks passed
@sashank-oai sashank-oai deleted the codex/revoke-tokens-on-logout branch April 17, 2026 05:51
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants