mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Centralize provider request preparation auth checks (#58121)
## What changed Move the model client's request-preparation loop into the shared `prepare_provider_request` helper and add `RequestAuthChange` to classify auth state changes. For managed auth, retry preparation when credentials change and reject account changes, including when the provider starts or stops exposing an auth manager during setup. Capture the auth owner and credential generations together and pass them into the preparation callback so the resulting client setup records the state used for that attempt. ## Testing Add a test verifying that an explicit provider bearer token survives a workspace switch during setup without retrying preparation. GitOrigin-RevId: ed8710d1c344b48ebf6182e25e6269214dd2d3fe
This commit is contained in:
@@ -19,6 +19,27 @@ pub struct AuthChangeState {
|
||||
pub login_generation: u64,
|
||||
}
|
||||
|
||||
/// Whether request preparation can use the credentials it selected.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum RequestAuthChange {
|
||||
Unchanged,
|
||||
CredentialsChanged,
|
||||
OwnerChanged,
|
||||
}
|
||||
|
||||
impl AuthChangeState {
|
||||
/// Compare a completed attempt with its original owner and starting credential revision.
|
||||
pub fn compare_for_request(&self, expected_owner: u64, prepared: Self) -> RequestAuthChange {
|
||||
if self.owner_generation != expected_owner {
|
||||
RequestAuthChange::OwnerChanged
|
||||
} else if self.generation != prepared.generation {
|
||||
RequestAuthChange::CredentialsChanged
|
||||
} else {
|
||||
RequestAuthChange::Unchanged
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn same_owner(previous: Option<&CodexAuth>, current: Option<&CodexAuth>) -> bool {
|
||||
let (Some(previous), Some(current)) = (previous, current) else {
|
||||
return false;
|
||||
|
||||
@@ -24,6 +24,7 @@ pub use bedrock_access_keys::login_with_bedrock_access_keys;
|
||||
pub use bedrock_api_key::BedrockApiKeyAuth;
|
||||
pub use bedrock_api_key::login_with_bedrock_api_key;
|
||||
pub use change_state::AuthChangeState;
|
||||
pub use change_state::RequestAuthChange;
|
||||
pub use error::RefreshTokenFailedError;
|
||||
pub use error::RefreshTokenFailedReason;
|
||||
pub use manager::*;
|
||||
|
||||
@@ -58,6 +58,7 @@ pub use auth::OPENAI_API_KEY_ENV_VAR;
|
||||
pub use auth::REFRESH_TOKEN_URL_OVERRIDE_ENV_VAR;
|
||||
pub use auth::REVOKE_TOKEN_URL_OVERRIDE_ENV_VAR;
|
||||
pub use auth::RefreshTokenError;
|
||||
pub use auth::RequestAuthChange;
|
||||
pub use auth::UnauthorizedRecovery;
|
||||
pub use auth::default_client;
|
||||
pub use auth::enforce_login_restrictions;
|
||||
|
||||
Reference in New Issue
Block a user