ChatGPT OAuth sign-in screen, reachable via /auth -> openai_codex.
Mirrors the MCP loopback flow in mcp_auth from the user's POV: a modal
shows progress, surfaces the authorize URL inline (so headless / SSH users
can copy it when the browser launch fails), and dismisses once the OAuth
callback completes. The OAuth primitives themselves (PKCE, callback HTTP
server, token exchange, refresh, atomic file write) are delegated to
langchain_openai.chatgpt_oauth via the
deepagents_code.integrations.openai_codex adapter.
Security notes:
notify never include
the access token, refresh token, or ID token.Open the ChatGPT account page in the user's browser.
Used by /auth to let signed-in users jump to chatgpt.com (e.g., to
change account, manage billing).
Run the ChatGPT OAuth Authorization Code Flow with PKCE inline.
Dismissal value:
True: a token was saved (caller should refresh provider lists /
retry the operation that needed the credential).False: the user cancelled, or the flow failed irrecoverably.The flow lives in a worker so the modal stays responsive to the cancel
keybinding while _wait_for_oauth_callback blocks for up to 5 minutes;
pressing Esc sets the worker's cancel_event, which frees the loopback
port within one poll interval rather than holding it until the timeout.
Outcome of the CodexSignedInScreen quick-action overlay.
Encoded as an enum (mirroring AuthResult) rather than bare strings so a
typo in either the producing action_* method or the consuming dispatch
is a type error, not a silent no-op.
Quick-action overlay shown when openai_codex is already signed in.
Dismissal values:
CodexSignedInAction.SIGN_OUT: delete the stored token.CodexSignedInAction.REAUTH: open the OAuth flow again.None: close without changes.ChatGPT OAuth integration for the openai_codex model provider.
Thin orchestration layer over langchain_openai.chatgpt_oauth. Reuses the
upstream PKCE/token primitives directly (_generate_pkce_pair,
_build_authorize_url, _CallbackHandler, _post_form,
_token_from_response, _FileChatGPTOAuthTokenProvider) so this module only
adds:
login_chatgpt
uses print(), which is invisible inside a Textual app),_wait_for_oauth_callback), and/auth to read sign-in status, expiry, and the linked account
without re-implementing token parsing.The browser-loopback flow mirrors the MCP one in mcp_auth from the user's
POV — PKCE + state CSRF + browser launch with a manual-URL fallback — but
the callback server here is upstream's single-threaded polling
http.server.HTTPServer (reused via _CallbackHandler), not the
ThreadingHTTPServer that mcp_auth runs itself. The OAuth-specific parts
(token exchange, refresh, file storage with 0600 perms) are delegated to
upstream.
The OAuth primitives are reused from langchain-openai>=1.3.1, which is
the first release to ship langchain_openai.chatgpt_oauth. This module
deliberately reaches into upstream-internal (_-prefixed) helpers; their
stability is an upstream concern, so pin the minimum langchain-openai
version when bumping and re-check the imported names against the release.