Conversation
65a3e63 to
d4cf2fa
Compare
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.
Summary
AuthManageralready owns persisted auth state andUnauthorizedRecoveryalready powers multi-step401recovery. The missing piece for dynamic provider tokens was scope: we needed a way for request paths to use an external bearer source without inventing a second auth abstraction incodex-coreor polluting the one global manager used by unrelated code.This PR refactors
AuthManagerso a derived manager instance can carry an external bearer refresher while sharing the underlying stored auth snapshot, forced workspace override, and refresh lock. That keeps the design simple: all request tokens still come fromAuthManager.auth(), and all401recovery still goes throughUnauthorizedRecovery.Motivation
This is groundwork for #15189.
That issue needs custom model providers to refresh short-lived bearer tokens dynamically, but the intended design is still:
AuthManagerencapsulates token storage and refreshUnauthorizedRecoverypowers staged401recoveryAuthManager.auth()By making external bearer auth instance-scoped on
AuthManager, the follow-on provider-auth PR can attach a command-backed token source to the request-facing managers used by normal API requests and/models, while leaving the base sessionAuthManageravailable for unrelated OpenAI auth use.What changed
AuthManagerinstance itselfAuthManager::with_external_bearer_refresher(...)so callers can derive a provider-scoped manager that shares persisted auth state and refresh coordination with the base managerAuthManager.auth()to resolve bearer-only external auth throughCodexAuth::ApiKeyauth.jsonpersistenceUnauthorizedRecoveryso the external path also works for bearer-only refreshersTesting
CARGO_TARGET_DIR=/tmp/codex-login-bearer-auth cargo test -p codex-login external_auth_tokens_without_chatgpt_metadata_cannot_seed_chatgpt_authCARGO_TARGET_DIR=/tmp/codex-login-auth-manager cargo test -p codex-login auth_manager_with_external_bearer_refresher_returns_provider_token_only_for_derived_managerCARGO_TARGET_DIR=/tmp/codex-login-auth-manager cargo test -p codex-login unauthorized_recovery_uses_external_refresh_for_bearer_managerCARGO_TARGET_DIR=/tmp/codex-login-auth-manager cargo check -p codex-app-serverStack created with Sapling. Best reviewed with ReviewStack.