diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json index b0504cf297..fdd5cccbe8 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -539,7 +539,7 @@ { "description": "[UNSTABLE] Backend auth supplied programmatically by the caller.\n\nRequest headers are kept in memory and are not persisted or refreshed by Codex.", "enum": [ - "callerProvided" + "externalProvided" ], "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json index 30934e5a89..72a33dd1b3 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json @@ -6953,7 +6953,7 @@ { "description": "[UNSTABLE] Backend auth supplied programmatically by the caller.\n\nRequest headers are kept in memory and are not persisted or refreshed by Codex.", "enum": [ - "callerProvided" + "externalProvided" ], "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json index 13401d8621..8d480474b3 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json @@ -1079,7 +1079,7 @@ { "description": "[UNSTABLE] Backend auth supplied programmatically by the caller.\n\nRequest headers are kept in memory and are not persisted or refreshed by Codex.", "enum": [ - "callerProvided" + "externalProvided" ], "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/json/v2/AccountUpdatedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/AccountUpdatedNotification.json index 60af99d96a..d492d5c2c2 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/AccountUpdatedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/AccountUpdatedNotification.json @@ -28,7 +28,7 @@ { "description": "[UNSTABLE] Backend auth supplied programmatically by the caller.\n\nRequest headers are kept in memory and are not persisted or refreshed by Codex.", "enum": [ - "callerProvided" + "externalProvided" ], "type": "string" }, diff --git a/codex-rs/app-server-protocol/schema/typescript/AuthMode.ts b/codex-rs/app-server-protocol/schema/typescript/AuthMode.ts index 55df5a1186..d1474c841c 100644 --- a/codex-rs/app-server-protocol/schema/typescript/AuthMode.ts +++ b/codex-rs/app-server-protocol/schema/typescript/AuthMode.ts @@ -5,4 +5,4 @@ /** * Authentication mode for OpenAI-backed providers. */ -export type AuthMode = "apikey" | "chatgpt" | "chatgptAuthTokens" | "callerProvided" | "agentIdentity" | "personalAccessToken" | "bedrockApiKey"; +export type AuthMode = "apikey" | "chatgpt" | "chatgptAuthTokens" | "externalProvided" | "agentIdentity" | "personalAccessToken" | "bedrockApiKey"; diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index 00d411d96a..7b13d09fe2 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -34,10 +34,10 @@ pub enum AuthMode { /// [UNSTABLE] Backend auth supplied programmatically by the caller. /// /// Request headers are kept in memory and are not persisted or refreshed by Codex. - #[serde(rename = "callerProvided")] - #[ts(rename = "callerProvided")] - #[strum(serialize = "callerProvided")] - CallerProvided, + #[serde(rename = "externalProvided")] + #[ts(rename = "externalProvided")] + #[strum(serialize = "externalProvided")] + ExternalProvided, /// Programmatic Codex auth backed by a registered Agent Identity. #[serde(rename = "agentIdentity")] #[ts(rename = "agentIdentity")] @@ -57,10 +57,13 @@ pub enum AuthMode { impl AuthMode { /// Returns whether this mode represents an authenticated human ChatGPT account. + /// + /// Externally provided auth configures this capability per auth instance, + /// so the mode alone cannot assert it. pub fn has_chatgpt_account(self) -> bool { match self { Self::Chatgpt | Self::ChatgptAuthTokens | Self::PersonalAccessToken => true, - Self::ApiKey | Self::CallerProvided | Self::AgentIdentity | Self::BedrockApiKey => { + Self::ApiKey | Self::ExternalProvided | Self::AgentIdentity | Self::BedrockApiKey => { false } } @@ -68,7 +71,7 @@ impl AuthMode { /// Returns whether this mode is backed by Codex services rather than a direct model API. /// - /// Caller-provided auth configures this capability per auth instance, so + /// Externally provided auth configures this capability per auth instance, so /// the mode alone cannot assert it. pub fn uses_codex_backend(self) -> bool { match self { @@ -76,7 +79,7 @@ impl AuthMode { | Self::ChatgptAuthTokens | Self::AgentIdentity | Self::PersonalAccessToken => true, - Self::ApiKey | Self::CallerProvided | Self::BedrockApiKey => false, + Self::ApiKey | Self::ExternalProvided | Self::BedrockApiKey => false, } } } diff --git a/codex-rs/app-server/src/auth_mode.rs b/codex-rs/app-server/src/auth_mode.rs index 9b1c0d8058..37fa065530 100644 --- a/codex-rs/app-server/src/auth_mode.rs +++ b/codex-rs/app-server/src/auth_mode.rs @@ -12,7 +12,7 @@ pub(crate) fn auth_mode_to_api(auth_mode: AuthMode) -> ApiAuthMode { AuthMode::ApiKey => ApiAuthMode::ApiKey, AuthMode::Chatgpt => ApiAuthMode::Chatgpt, AuthMode::ChatgptAuthTokens => ApiAuthMode::ChatgptAuthTokens, - AuthMode::CallerProvided => ApiAuthMode::CallerProvided, + AuthMode::ExternalProvided => ApiAuthMode::ExternalProvided, AuthMode::AgentIdentity => ApiAuthMode::AgentIdentity, AuthMode::PersonalAccessToken => ApiAuthMode::PersonalAccessToken, AuthMode::BedrockApiKey => ApiAuthMode::BedrockApiKey, diff --git a/codex-rs/app-server/src/request_processors/account_processor.rs b/codex-rs/app-server/src/request_processors/account_processor.rs index 986e4de665..e854266d50 100644 --- a/codex-rs/app-server/src/request_processors/account_processor.rs +++ b/codex-rs/app-server/src/request_processors/account_processor.rs @@ -812,7 +812,7 @@ impl AccountRequestProcessor { let auth_mode = auth_mode_to_api(auth.api_auth_mode()); let (reported_auth_method, token_opt) = if matches!( auth, - CodexAuth::CallerProvided(_) + CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) ) || include_token diff --git a/codex-rs/cli/src/doctor.rs b/codex-rs/cli/src/doctor.rs index 9aff965abf..77f2b4dea5 100644 --- a/codex-rs/cli/src/doctor.rs +++ b/codex-rs/cli/src/doctor.rs @@ -1327,7 +1327,7 @@ fn stored_auth_mode(auth: &codex_login::AuthDotJson) -> &'static str { AuthMode::ApiKey => "api_key", AuthMode::Chatgpt => "chatgpt", AuthMode::ChatgptAuthTokens => "chatgpt_auth_tokens", - AuthMode::CallerProvided => "caller_provided", + AuthMode::ExternalProvided => "external_provided", AuthMode::AgentIdentity => "agent_identity", AuthMode::PersonalAccessToken => "personal_access_token", AuthMode::BedrockApiKey => "bedrock_api_key", @@ -1398,8 +1398,8 @@ fn stored_auth_issues( issues.push("external ChatGPT auth is missing refresh metadata"); } } - AuthMode::CallerProvided => { - issues.push("caller-provided auth cannot be loaded from auth storage"); + AuthMode::ExternalProvided => { + issues.push("externally provided auth cannot be loaded from auth storage"); } AuthMode::AgentIdentity => { if auth @@ -2470,7 +2470,7 @@ fn auth_mode_name(auth: &CodexAuth) -> &'static str { AuthMode::ApiKey => "api_key", AuthMode::Chatgpt => "chatgpt", AuthMode::ChatgptAuthTokens => "chatgpt_auth_tokens", - AuthMode::CallerProvided => "caller_provided", + AuthMode::ExternalProvided => "external_provided", AuthMode::AgentIdentity => "agent_identity", AuthMode::PersonalAccessToken => "personal_access_token", AuthMode::BedrockApiKey => "bedrock_api_key", @@ -2610,7 +2610,7 @@ fn provider_auth_reachability_mode_from_auth( Some( AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens - | AuthMode::CallerProvided + | AuthMode::ExternalProvided | AuthMode::AgentIdentity | AuthMode::PersonalAccessToken, ) diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rs index b44f777658..c52668658f 100644 --- a/codex-rs/cli/src/login.rs +++ b/codex-rs/cli/src/login.rs @@ -449,8 +449,8 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! { eprintln!("Logged in using ChatGPT"); std::process::exit(0); } - AuthMode::CallerProvided => { - eprintln!("Logged in using caller-provided auth"); + AuthMode::ExternalProvided => { + eprintln!("Logged in using externally provided auth"); std::process::exit(0); } AuthMode::AgentIdentity => { diff --git a/codex-rs/codex-mcp/src/connection_manager_tests.rs b/codex-rs/codex-mcp/src/connection_manager_tests.rs index 0f21cb5ac4..789a33df23 100644 --- a/codex-rs/codex-mcp/src/connection_manager_tests.rs +++ b/codex-rs/codex-mcp/src/connection_manager_tests.rs @@ -26,8 +26,8 @@ use codex_config::McpServerToolConfig; use codex_config::types::AuthKeyringBackendKind; use codex_config::types::OAuthCredentialsStoreMode; use codex_exec_server::EnvironmentManager; -use codex_login::CallerProvidedAuth; use codex_login::CodexAuth; +use codex_login::ExternalProvidedAuth; use codex_protocol::ToolName; use codex_protocol::mcp::McpServerInfo; use codex_protocol::models::PermissionProfile; @@ -71,9 +71,9 @@ fn create_test_tool(server_name: &str, tool_name: &str) -> ToolInfo { } #[test] -fn caller_provided_auth_scopes_codex_apps_cache() { - let auth = CodexAuth::CallerProvided( - CallerProvidedAuth::new([], "user-123").with_account_id("account-123"), +fn external_provided_auth_scopes_codex_apps_cache() { + let auth = CodexAuth::ExternalProvided( + ExternalProvidedAuth::new([], "user-123").with_account_id("account-123"), ); assert_eq!( diff --git a/codex-rs/core-api/src/lib.rs b/codex-rs/core-api/src/lib.rs index 096a29be0a..4f7694f36d 100644 --- a/codex-rs/core-api/src/lib.rs +++ b/codex-rs/core-api/src/lib.rs @@ -70,8 +70,8 @@ pub use codex_features::Feature; pub use codex_features::Features; pub use codex_home::CodexHomeUserInstructionsProvider; pub use codex_login::AuthManager; -pub use codex_login::CallerProvidedAuth; -pub use codex_login::CallerProvidedAuthCapabilities; +pub use codex_login::ExternalProvidedAuth; +pub use codex_login::ExternalProvidedAuthCapabilities; pub use codex_login::default_client::set_default_originator; pub use codex_model_provider_info::OPENAI_PROVIDER_ID; pub use codex_model_provider_info::built_in_model_providers; diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index d2dc269a3b..12b4abf688 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -69,7 +69,6 @@ use codex_login::UnauthorizedRecovery; use codex_login::default_client::build_reqwest_client; use codex_otel::SessionTelemetry; use codex_otel::current_span_w3c_trace_context; -use codex_protocol::auth::AuthMode; use codex_protocol::ThreadId; use codex_protocol::config_types::ReasoningSummary as ReasoningSummaryConfig; @@ -536,7 +535,7 @@ impl ModelClient { let request_telemetry = Self::build_request_telemetry( session_telemetry, AuthRequestTelemetryContext::new( - client_setup.auth.as_ref().map(CodexAuth::auth_mode), + client_setup.auth.as_ref(), client_setup.api_auth.as_ref(), client_setup.agent_identity_telemetry.clone(), PendingUnauthorizedRetry::default(), @@ -669,7 +668,7 @@ impl ModelClient { let request_telemetry = Self::build_request_telemetry( session_telemetry, AuthRequestTelemetryContext::new( - client_setup.auth.as_ref().map(CodexAuth::auth_mode), + client_setup.auth.as_ref(), client_setup.api_auth.as_ref(), client_setup.agent_identity_telemetry.clone(), PendingUnauthorizedRetry::default(), @@ -1229,7 +1228,7 @@ impl ModelClientSession { )) })?; let auth_context = AuthRequestTelemetryContext::new( - client_setup.auth.as_ref().map(CodexAuth::auth_mode), + client_setup.auth.as_ref(), client_setup.api_auth.as_ref(), client_setup.agent_identity_telemetry.clone(), PendingUnauthorizedRetry::default(), @@ -1368,7 +1367,7 @@ impl ModelClientSession { let client_setup = self.client.current_client_setup().await?; let transport = ReqwestTransport::new(build_reqwest_client()); let request_auth_context = AuthRequestTelemetryContext::new( - client_setup.auth.as_ref().map(CodexAuth::auth_mode), + client_setup.auth.as_ref(), client_setup.api_auth.as_ref(), client_setup.agent_identity_telemetry.clone(), pending_retry, @@ -1496,7 +1495,7 @@ impl ModelClientSession { loop { let client_setup = self.client.current_client_setup().await?; let request_auth_context = AuthRequestTelemetryContext::new( - client_setup.auth.as_ref().map(CodexAuth::auth_mode), + client_setup.auth.as_ref(), client_setup.api_auth.as_ref(), client_setup.agent_identity_telemetry.clone(), pending_retry, @@ -2077,20 +2076,19 @@ struct AuthRequestTelemetryContext { impl AuthRequestTelemetryContext { fn new( - auth_mode: Option, + auth: Option<&CodexAuth>, api_auth: &dyn AuthProvider, agent_identity_telemetry: Option, retry: PendingUnauthorizedRetry, ) -> Self { let auth_telemetry = auth_header_telemetry(api_auth); Self { - auth_mode: auth_mode.map(|mode| match mode { - AuthMode::ApiKey | AuthMode::BedrockApiKey => "ApiKey", - AuthMode::Chatgpt - | AuthMode::ChatgptAuthTokens - | AuthMode::CallerProvided - | AuthMode::AgentIdentity - | AuthMode::PersonalAccessToken => "Chatgpt", + auth_mode: auth.map(|auth| { + if auth.uses_codex_backend() { + "Chatgpt" + } else { + "ApiKey" + } }), auth_header_attached: auth_telemetry.attached, auth_header_name: auth_telemetry.name, diff --git a/codex-rs/core/src/client_tests.rs b/codex-rs/core/src/client_tests.rs index dd2b1079f7..87e520052e 100644 --- a/codex-rs/core/src/client_tests.rs +++ b/codex-rs/core/src/client_tests.rs @@ -23,6 +23,8 @@ use codex_login::AuthCredentialsStoreMode; use codex_login::AuthKeyringBackendKind; use codex_login::AuthManager; use codex_login::CodexAuth; +use codex_login::ExternalProvidedAuth; +use codex_login::ExternalProvidedAuthCapabilities; use codex_login::auth::AgentIdentityAuthPolicy; use codex_model_provider::BearerAuthProvider; use codex_model_provider::SharedModelProvider; @@ -33,7 +35,6 @@ use codex_model_provider_info::WireApi; use codex_model_provider_info::create_oss_provider_with_base_url; use codex_otel::SessionTelemetry; use codex_protocol::ThreadId; -use codex_protocol::auth::AuthMode; use codex_protocol::models::BaseInstructions; use codex_protocol::models::ContentItem; use codex_protocol::models::ResponseItem; @@ -738,8 +739,15 @@ async fn dropped_backpressured_response_stream_traces_cancelled_partial_output() #[test] fn auth_request_telemetry_context_tracks_attached_auth_and_retry_phase() { + let auth = + CodexAuth::ExternalProvided(ExternalProvidedAuth::new([], "user-123").with_capabilities( + ExternalProvidedAuthCapabilities { + uses_codex_backend: true, + ..Default::default() + }, + )); let auth_context = AuthRequestTelemetryContext::new( - Some(AuthMode::Chatgpt), + Some(&auth), &BearerAuthProvider::for_test(Some("access-token"), Some("workspace-123")), /*agent_identity_telemetry*/ None, PendingUnauthorizedRetry::from_recovery(UnauthorizedRecoveryExecution { @@ -758,8 +766,9 @@ fn auth_request_telemetry_context_tracks_attached_auth_and_retry_phase() { #[test] fn auth_request_telemetry_context_tracks_agent_identity_ids() { + let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing(); let auth_context = AuthRequestTelemetryContext::new( - Some(AuthMode::Chatgpt), + Some(&auth), &BearerAuthProvider::for_test(/*token*/ None, /*account_id*/ None), Some(AgentIdentityTelemetry { agent_id: "agent-runtime-context".to_string(), diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 3470e30826..b9cf093f69 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -71,8 +71,8 @@ use codex_exec_server::LOCAL_FS; use codex_features::Feature; use codex_features::FeaturesToml; use codex_login::AuthManager; -use codex_login::CallerProvidedAuth; -use codex_login::CallerProvidedAuthCapabilities; +use codex_login::ExternalProvidedAuth; +use codex_login::ExternalProvidedAuthCapabilities; use codex_model_provider_info::LMSTUDIO_OSS_PROVIDER_ID; use codex_model_provider_info::OLLAMA_OSS_PROVIDER_ID; use codex_model_provider_info::WireApi; @@ -203,22 +203,23 @@ async fn derive_legacy_sandbox_policy_for_test( } #[tokio::test] -async fn caller_provided_auth_is_installed_from_runtime_config() -> std::io::Result<()> { +async fn external_provided_auth_is_installed_from_runtime_config() -> std::io::Result<()> { let codex_home = tempdir()?; let mut config = ConfigBuilder::default() .codex_home(codex_home.path().to_path_buf()) .fallback_cwd(Some(codex_home.path().to_path_buf())) .build() .await?; - config.caller_provided_auth = Some(CallerProvidedAuth::new([], "user-123").with_capabilities( - CallerProvidedAuthCapabilities { - uses_codex_backend: true, - ..Default::default() - }, - )); + config.external_provided_auth = + Some(ExternalProvidedAuth::new([], "user-123").with_capabilities( + ExternalProvidedAuthCapabilities { + uses_codex_backend: true, + ..Default::default() + }, + )); let auth_manager = AuthManager::shared_from_config(&config, false).await; - let auth = auth_manager.auth().await.expect("caller auth"); + let auth = auth_manager.auth().await.expect("external auth"); assert!(auth.uses_codex_backend()); assert!(!auth.is_chatgpt_auth()); diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 9ab4ed4d22..e02f4e5848 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -72,7 +72,7 @@ use codex_git_utils::resolve_root_git_project_for_trust; use codex_install_context::InstallContext; use codex_login::AuthManagerConfig; use codex_login::AuthRouteConfig; -use codex_login::CallerProvidedAuth; +use codex_login::ExternalProvidedAuth; use codex_mcp::McpConfig; use codex_mcp::McpPluginAttribution; use codex_mcp::McpServerRegistration; @@ -820,7 +820,7 @@ pub struct Config { /// In-memory auth supplied by a trusted embedding runtime. /// /// This is never loaded from config files or user overrides. - pub caller_provided_auth: Option, + pub external_provided_auth: Option, /// Definition for MCP servers that Codex can reach out to for tool calls. pub mcp_servers: Constrained>, @@ -1227,8 +1227,8 @@ impl AuthManagerConfig for Config { Config::auth_route_config(self) } - fn caller_provided_auth(&self) -> Option { - self.caller_provided_auth.clone() + fn external_provided_auth(&self) -> Option { + self.external_provided_auth.clone() } } @@ -3810,7 +3810,7 @@ impl Config { cfg.cli_auth_credentials_store.unwrap_or_default(), env!("CARGO_PKG_VERSION"), ), - caller_provided_auth: None, + external_provided_auth: None, mcp_servers, // The config.toml omits "_mode" because it's a config file. However, "_mode" // is important in code to differentiate the mode from the store implementation. diff --git a/codex-rs/ext/mcp/tests/hosted_apps_mcp.rs b/codex-rs/ext/mcp/tests/hosted_apps_mcp.rs index 9c934465fc..c06956de7c 100644 --- a/codex-rs/ext/mcp/tests/hosted_apps_mcp.rs +++ b/codex-rs/ext/mcp/tests/hosted_apps_mcp.rs @@ -9,9 +9,9 @@ use codex_extension_api::ExtensionRegistryBuilder; use codex_extension_api::McpServerContribution; use codex_extension_api::McpServerContributionContext; use codex_extension_api::McpServerContributor; -use codex_login::CallerProvidedAuth; -use codex_login::CallerProvidedAuthCapabilities; use codex_login::CodexAuth; +use codex_login::ExternalProvidedAuth; +use codex_login::ExternalProvidedAuthCapabilities; use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; use pretty_assertions::assert_eq; @@ -149,7 +149,7 @@ async fn hosted_apps_mcp_requires_chatgpt_auth() -> TestResult { } #[tokio::test] -async fn hosted_apps_mcp_accepts_caller_provided_codex_auth() -> TestResult { +async fn hosted_apps_mcp_accepts_external_provided_codex_auth() -> TestResult { let codex_home = tempfile::tempdir()?; let config = ConfigBuilder::default() .codex_home(codex_home.path().to_path_buf()) @@ -157,12 +157,13 @@ async fn hosted_apps_mcp_accepts_caller_provided_codex_auth() -> TestResult { .cli_overrides(vec![("features.apps".to_string(), true.into())]) .build() .await?; - let auth = CodexAuth::CallerProvided( - CallerProvidedAuth::new([], "user-123").with_capabilities(CallerProvidedAuthCapabilities { - uses_codex_backend: true, - ..Default::default() - }), - ); + let auth = + CodexAuth::ExternalProvided(ExternalProvidedAuth::new([], "user-123").with_capabilities( + ExternalProvidedAuthCapabilities { + uses_codex_backend: true, + ..Default::default() + }, + )); let manager = installed_manager(&config); let servers = manager.effective_servers(&config, Some(&auth)).await; diff --git a/codex-rs/login/src/auth/auth_tests.rs b/codex-rs/login/src/auth/auth_tests.rs index 9509cab456..629e4c8813 100644 --- a/codex-rs/login/src/auth/auth_tests.rs +++ b/codex-rs/login/src/auth/auth_tests.rs @@ -31,6 +31,25 @@ const WORKSPACE_ID_ALLOWED: &str = "123e4567-e89b-42d3-a456-426614174000"; const WORKSPACE_ID_SECOND_ALLOWED: &str = "123e4567-e89b-42d3-a456-426614174001"; const WORKSPACE_ID_DISALLOWED: &str = "123e4567-e89b-42d3-a456-426614174002"; +#[test] +fn externally_provided_auth_delegates_account_metadata() { + let auth = CodexAuth::ExternalProvided( + ExternalProvidedAuth::new([], "user-123") + .with_account_email("user@example.com") + .with_account_plan_type(AccountPlanType::Pro) + .with_fedramp_account(true), + ); + + assert!(auth.is_fedramp_account()); + assert_eq!(auth.api_key(), None); + assert!(auth.get_token().is_err()); + assert_eq!( + auth.get_account_email().as_deref(), + Some("user@example.com") + ); + assert_eq!(auth.account_plan_type(), Some(AccountPlanType::Pro)); +} + #[tokio::test] async fn refresh_without_id_token() { let codex_home = tempdir().unwrap(); diff --git a/codex-rs/login/src/auth/bedrock_api_key_tests.rs b/codex-rs/login/src/auth/bedrock_api_key_tests.rs index ef87c7439c..fe7f2ad8c8 100644 --- a/codex-rs/login/src/auth/bedrock_api_key_tests.rs +++ b/codex-rs/login/src/auth/bedrock_api_key_tests.rs @@ -85,7 +85,7 @@ async fn login_with_bedrock_api_key_replaces_openai_auth() -> anyhow::Result<()> CodexAuth::ApiKey(_) | CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) - | CodexAuth::CallerProvided(_) + | CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) => None, }), @@ -149,7 +149,7 @@ async fn bedrock_only_auth_storage_creates_primary_auth() -> anyhow::Result<()> CodexAuth::ApiKey(_) | CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) - | CodexAuth::CallerProvided(_) + | CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) => None, }), diff --git a/codex-rs/login/src/auth/caller_provided.rs b/codex-rs/login/src/auth/caller_provided.rs deleted file mode 100644 index 6b3b3b942a..0000000000 --- a/codex-rs/login/src/auth/caller_provided.rs +++ /dev/null @@ -1,108 +0,0 @@ -use std::collections::BTreeMap; -use std::fmt; - -/// Backend authentication supplied programmatically by the caller. -/// -/// The caller owns credential validation, rotation, and persistence. -/// Codex keeps this snapshot in memory and uses its headers for backend requests. -#[derive(Clone, PartialEq, Eq)] -pub struct CallerProvidedAuth { - headers: BTreeMap, - account_id: Option, - user_id: String, - capabilities: CallerProvidedAuthCapabilities, -} - -/// Behavior explicitly enabled by the caller that supplies -/// [CallerProvidedAuth]. -/// -/// All capabilities default to disabled. Callers should only enable behavior -/// that is supported by the credentials they provide. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -pub struct CallerProvidedAuthCapabilities { - /// Whether these credentials can authenticate requests to Codex backend - /// services. - pub uses_codex_backend: bool, - /// Whether these credentials represent an authenticated human ChatGPT - /// account. - pub has_chatgpt_account: bool, -} - -impl fmt::Debug for CallerProvidedAuth { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("CallerProvidedAuth") - .field("headers", &"") - .field("account_id", &self.account_id) - .field("user_id", &self.user_id) - .field("capabilities", &self.capabilities) - .finish() - } -} - -impl CallerProvidedAuth { - /// Creates caller-provided auth with backend request headers and a stable user identity. - pub fn new( - headers: impl IntoIterator, - user_id: impl Into, - ) -> Self { - Self { - headers: headers.into_iter().collect(), - account_id: None, - user_id: user_id.into(), - capabilities: CallerProvidedAuthCapabilities::default(), - } - } - - /// Adds the account selected by the caller. - pub fn with_account_id(mut self, account_id: impl Into) -> Self { - self.account_id = Some(account_id.into()); - self - } - - /// Sets the behavior supported by these caller-provided credentials. - pub fn with_capabilities(mut self, capabilities: CallerProvidedAuthCapabilities) -> Self { - self.capabilities = capabilities; - self - } - - /// Returns the request headers supplied by the caller. - pub fn headers(&self) -> &BTreeMap { - &self.headers - } - - /// Returns the selected account ID, when the caller supplied one. - pub fn account_id(&self) -> Option<&str> { - self.account_id.as_deref() - } - - /// Returns the stable user ID supplied by the caller. - pub fn user_id(&self) -> &str { - &self.user_id - } - - /// Returns the behavior supported by these caller-provided credentials. - pub fn capabilities(&self) -> CallerProvidedAuthCapabilities { - self.capabilities - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn capabilities_are_disabled_until_the_caller_enables_them() { - let auth = CallerProvidedAuth::new([], "user-123"); - assert_eq!( - auth.capabilities(), - CallerProvidedAuthCapabilities::default() - ); - - let auth = auth.with_capabilities(CallerProvidedAuthCapabilities { - uses_codex_backend: true, - has_chatgpt_account: true, - }); - assert!(auth.capabilities().uses_codex_backend); - assert!(auth.capabilities().has_chatgpt_account); - } -} diff --git a/codex-rs/login/src/auth/external_provided.rs b/codex-rs/login/src/auth/external_provided.rs new file mode 100644 index 0000000000..e61a0d198f --- /dev/null +++ b/codex-rs/login/src/auth/external_provided.rs @@ -0,0 +1,177 @@ +use std::collections::BTreeMap; +use std::fmt; + +use codex_protocol::account::PlanType as AccountPlanType; + +/// Backend authentication supplied programmatically by the caller. +/// +/// The caller owns credential validation, rotation, and persistence. +/// Codex keeps this snapshot in memory and uses its headers for backend requests. +#[derive(Clone, PartialEq, Eq)] +pub struct ExternalProvidedAuth { + headers: BTreeMap, + account_id: Option, + user_id: String, + account_email: Option, + account_plan_type: Option, + is_fedramp_account: bool, + capabilities: ExternalProvidedAuthCapabilities, +} + +/// Behavior explicitly enabled by the caller that supplies +/// [ExternalProvidedAuth]. +/// +/// All capabilities default to disabled. Callers should only enable behavior +/// that is supported by the credentials they provide. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct ExternalProvidedAuthCapabilities { + /// Whether these credentials can authenticate requests to Codex backend + /// services. + pub uses_codex_backend: bool, + /// Whether these credentials represent an authenticated human ChatGPT + /// account. + pub has_chatgpt_account: bool, +} + +impl fmt::Debug for ExternalProvidedAuth { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ExternalProvidedAuth") + .field("headers", &"") + .field("account_id", &self.account_id) + .field("user_id", &self.user_id) + .field( + "account_email", + &self.account_email.as_ref().map(|_| ""), + ) + .field("account_plan_type", &self.account_plan_type) + .field("is_fedramp_account", &self.is_fedramp_account) + .field("capabilities", &self.capabilities) + .finish() + } +} + +impl ExternalProvidedAuth { + /// Creates externally provided auth with backend request headers and a stable user identity. + pub fn new( + headers: impl IntoIterator, + user_id: impl Into, + ) -> Self { + Self { + headers: headers.into_iter().collect(), + account_id: None, + user_id: user_id.into(), + account_email: None, + account_plan_type: Some(AccountPlanType::Unknown), + is_fedramp_account: false, + capabilities: ExternalProvidedAuthCapabilities::default(), + } + } + + /// Adds the account selected by the caller. + pub fn with_account_id(mut self, account_id: impl Into) -> Self { + self.account_id = Some(account_id.into()); + self + } + + /// Adds the account email supplied by the caller. + pub fn with_account_email(mut self, account_email: impl Into) -> Self { + self.account_email = Some(account_email.into()); + self + } + + /// Adds the account plan classification supplied by the caller. + pub fn with_account_plan_type(mut self, account_plan_type: AccountPlanType) -> Self { + self.account_plan_type = Some(account_plan_type); + self + } + + /// Sets whether the supplied account is a FedRAMP account. + pub fn with_fedramp_account(mut self, is_fedramp_account: bool) -> Self { + self.is_fedramp_account = is_fedramp_account; + self + } + + /// Sets the behavior supported by these externally provided credentials. + pub fn with_capabilities(mut self, capabilities: ExternalProvidedAuthCapabilities) -> Self { + self.capabilities = capabilities; + self + } + + /// Returns the request headers supplied by the caller. + pub fn headers(&self) -> &BTreeMap { + &self.headers + } + + /// Returns the selected account ID, when the caller supplied one. + pub fn account_id(&self) -> Option<&str> { + self.account_id.as_deref() + } + + /// Returns the account email supplied by the caller. + pub fn account_email(&self) -> Option<&str> { + self.account_email.as_deref() + } + + /// Returns the account plan classification supplied by the caller. + pub fn account_plan_type(&self) -> Option { + self.account_plan_type.clone() + } + + /// Returns whether the supplied account is a FedRAMP account. + pub fn is_fedramp_account(&self) -> bool { + self.is_fedramp_account + } + + /// Returns the stable user ID supplied by the caller. + pub fn user_id(&self) -> &str { + &self.user_id + } + + /// Returns the behavior supported by these externally provided credentials. + pub fn capabilities(&self) -> ExternalProvidedAuthCapabilities { + self.capabilities + } + + /// Returns whether these credentials represent an authenticated human ChatGPT account. + pub fn has_chatgpt_account(&self) -> bool { + self.capabilities.has_chatgpt_account + } + + /// Returns whether these credentials can authenticate requests to Codex backend services. + pub fn uses_codex_backend(&self) -> bool { + self.capabilities.uses_codex_backend + } + + /// Externally provided header auth does not expose an API key. + pub fn api_key(&self) -> Option<&str> { + None + } + + /// Externally provided header auth does not expose a bearer token. + pub fn bearer_token(&self) -> Result { + Err(std::io::Error::other( + "externally provided auth does not expose a bearer token", + )) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn capabilities_are_disabled_until_the_caller_enables_them() { + let auth = ExternalProvidedAuth::new([], "user-123"); + assert_eq!( + auth.capabilities(), + ExternalProvidedAuthCapabilities::default() + ); + + let auth = auth.with_capabilities(ExternalProvidedAuthCapabilities { + uses_codex_backend: true, + has_chatgpt_account: true, + }); + assert!(auth.capabilities().uses_codex_backend); + assert!(auth.capabilities().has_chatgpt_account); + } +} diff --git a/codex-rs/login/src/auth/manager.rs b/codex-rs/login/src/auth/manager.rs index 16800e5fba..e31fe41894 100644 --- a/codex-rs/login/src/auth/manager.rs +++ b/codex-rs/login/src/auth/manager.rs @@ -41,7 +41,7 @@ use super::revoke::revoke_auth_tokens; pub use crate::auth::agent_identity::AgentIdentityAuth; pub use crate::auth::agent_identity::AgentIdentityAuthError; pub use crate::auth::bedrock_api_key::BedrockApiKeyAuth; -use crate::auth::caller_provided::CallerProvidedAuth; +use crate::auth::external_provided::ExternalProvidedAuth; pub use crate::auth::personal_access_token::PersonalAccessTokenAuth; pub use crate::auth::storage::AgentIdentityAuthRecord; pub use crate::auth::storage::AgentIdentityStorage; @@ -72,7 +72,7 @@ pub enum CodexAuth { ApiKey(ApiKeyAuth), Chatgpt(ChatgptAuth), ChatgptAuthTokens(ChatgptAuthTokens), - CallerProvided(CallerProvidedAuth), + ExternalProvided(ExternalProvidedAuth), AgentIdentity(AgentIdentityAuth), PersonalAccessToken(PersonalAccessTokenAuth), BedrockApiKey(BedrockApiKeyAuth), @@ -147,7 +147,7 @@ impl AgentIdentityBootstrapCooldown { impl PartialEq for CodexAuth { fn eq(&self, other: &Self) -> bool { match (self, other) { - (Self::CallerProvided(a), Self::CallerProvided(b)) => a == b, + (Self::ExternalProvided(a), Self::ExternalProvided(b)) => a == b, (Self::PersonalAccessToken(a), Self::PersonalAccessToken(b)) => a == b, (Self::BedrockApiKey(a), Self::BedrockApiKey(b)) => a == b, _ => self.api_auth_mode() == other.api_auth_mode(), @@ -360,9 +360,9 @@ impl CodexAuth { }; return Ok(Self::BedrockApiKey(auth)); } - if auth_mode == AuthMode::CallerProvided { + if auth_mode == AuthMode::ExternalProvided { return Err(std::io::Error::other( - "caller-provided auth cannot be loaded from auth storage.", + "externally provided auth cannot be loaded from auth storage.", )); } @@ -384,8 +384,8 @@ impl CodexAuth { } AuthMode::ChatgptAuthTokens => Ok(Self::ChatgptAuthTokens(ChatgptAuthTokens { state })), AuthMode::ApiKey => unreachable!("api key mode is handled above"), - AuthMode::CallerProvided => { - unreachable!("caller-provided auth is never loaded from auth storage") + AuthMode::ExternalProvided => { + unreachable!("externally provided auth is never loaded from auth storage") } AuthMode::AgentIdentity => unreachable!("agent identity mode is handled above"), AuthMode::PersonalAccessToken => { @@ -469,7 +469,7 @@ impl CodexAuth { match self { Self::ApiKey(_) => AuthMode::ApiKey, Self::Chatgpt(_) | Self::ChatgptAuthTokens(_) => AuthMode::Chatgpt, - Self::CallerProvided(_) => AuthMode::CallerProvided, + Self::ExternalProvided(_) => AuthMode::ExternalProvided, Self::AgentIdentity(_) => AuthMode::AgentIdentity, Self::PersonalAccessToken(_) => AuthMode::PersonalAccessToken, Self::BedrockApiKey(_) => AuthMode::BedrockApiKey, @@ -482,7 +482,7 @@ impl CodexAuth { Self::ApiKey(_) => AuthMode::ApiKey, Self::Chatgpt(_) => AuthMode::Chatgpt, Self::ChatgptAuthTokens(_) => AuthMode::ChatgptAuthTokens, - Self::CallerProvided(_) => AuthMode::CallerProvided, + Self::ExternalProvided(_) => AuthMode::ExternalProvided, Self::AgentIdentity(_) => AuthMode::AgentIdentity, Self::PersonalAccessToken(_) => AuthMode::PersonalAccessToken, Self::BedrockApiKey(_) => AuthMode::BedrockApiKey, @@ -499,14 +499,14 @@ impl CodexAuth { pub fn is_chatgpt_auth(&self) -> bool { match self { - Self::CallerProvided(auth) => auth.capabilities().has_chatgpt_account, + Self::ExternalProvided(auth) => auth.has_chatgpt_account(), _ => self.api_auth_mode().has_chatgpt_account(), } } pub fn uses_codex_backend(&self) -> bool { match self { - Self::CallerProvided(auth) => auth.capabilities().uses_codex_backend, + Self::ExternalProvided(auth) => auth.uses_codex_backend(), _ => self.api_auth_mode().uses_codex_backend(), } } @@ -523,9 +523,9 @@ impl CodexAuth { pub fn api_key(&self) -> Option<&str> { match self { Self::ApiKey(auth) => Some(auth.api_key.as_str()), + Self::ExternalProvided(auth) => auth.api_key(), Self::Chatgpt(_) | Self::ChatgptAuthTokens(_) - | Self::CallerProvided(_) | Self::AgentIdentity(_) | Self::PersonalAccessToken(_) | Self::BedrockApiKey(_) => None, @@ -556,9 +556,7 @@ impl CodexAuth { Self::AgentIdentity(_) => Err(std::io::Error::other( "agent identity auth does not expose a bearer token", )), - Self::CallerProvided(_) => Err(std::io::Error::other( - "caller-provided auth does not expose a bearer token", - )), + Self::ExternalProvided(auth) => auth.bearer_token(), Self::PersonalAccessToken(auth) => Ok(auth.access_token().to_string()), Self::BedrockApiKey(_) => Err(std::io::Error::other( "Bedrock API key auth does not expose a Codex bearer token", @@ -569,7 +567,7 @@ impl CodexAuth { /// Returns `None` if Codex backend auth does not expose an account id. pub fn get_account_id(&self) -> Option { match self { - Self::CallerProvided(auth) => auth.account_id().map(str::to_string), + Self::ExternalProvided(auth) => auth.account_id().map(str::to_string), Self::AgentIdentity(auth) => Some(auth.account_id().to_string()), Self::PersonalAccessToken(auth) => Some(auth.account_id().to_string()), _ => self.get_current_token_data().and_then(|t| t.account_id), @@ -579,7 +577,7 @@ impl CodexAuth { /// Returns false if Codex backend auth omits the FedRAMP claim. pub fn is_fedramp_account(&self) -> bool { match self { - Self::CallerProvided(_) => false, + Self::ExternalProvided(auth) => auth.is_fedramp_account(), Self::AgentIdentity(auth) => auth.is_fedramp_account(), Self::PersonalAccessToken(auth) => auth.is_fedramp_account(), _ => self @@ -591,7 +589,7 @@ impl CodexAuth { /// Returns `None` if Codex backend auth does not expose an account email. pub fn get_account_email(&self) -> Option { match self { - Self::CallerProvided(_) => None, + Self::ExternalProvided(auth) => auth.account_email().map(str::to_string), Self::AgentIdentity(auth) => auth.email().map(str::to_string), Self::PersonalAccessToken(auth) => auth.email().map(str::to_string), _ => self.get_current_token_data().and_then(|t| t.id_token.email), @@ -601,7 +599,7 @@ impl CodexAuth { /// Returns `None` if Codex backend auth does not expose a ChatGPT user id. pub fn get_chatgpt_user_id(&self) -> Option { match self { - Self::CallerProvided(auth) => Some(auth.user_id().to_string()), + Self::ExternalProvided(auth) => Some(auth.user_id().to_string()), Self::AgentIdentity(auth) => Some(auth.chatgpt_user_id().to_string()), Self::PersonalAccessToken(auth) => Some(auth.chatgpt_user_id().to_string()), _ => self @@ -614,8 +612,8 @@ impl CodexAuth { /// Returns a high-level `AccountPlanType` (e.g., Free/Plus/Pro/Team/…) /// for UI or product decisions based on the user's subscription. pub fn account_plan_type(&self) -> Option { - if matches!(self, Self::CallerProvided(_)) { - return Some(AccountPlanType::Unknown); + if let Self::ExternalProvided(auth) = self { + return auth.account_plan_type(); } if let Self::AgentIdentity(auth) = self { return Some(auth.plan_type()); @@ -643,7 +641,7 @@ impl CodexAuth { Self::Chatgpt(auth) => &auth.state, Self::ChatgptAuthTokens(auth) => &auth.state, Self::ApiKey(_) - | Self::CallerProvided(_) + | Self::ExternalProvided(_) | Self::AgentIdentity(_) | Self::PersonalAccessToken(_) | Self::BedrockApiKey(_) => return None, @@ -689,7 +687,7 @@ impl CodexAuth { Self::AgentIdentity(auth) => Ok(Some(auth.clone())), Self::ApiKey(_) | Self::ChatgptAuthTokens(_) - | Self::CallerProvided(_) + | Self::ExternalProvided(_) | Self::PersonalAccessToken(_) | Self::BedrockApiKey(_) => Ok(None), Self::Chatgpt(_) => { @@ -1118,12 +1116,12 @@ async fn enforce_login_restrictions_with_agent_identity_authapi_base_url( | (ForcedLoginMethod::Api, AuthMode::BedrockApiKey) => None, (ForcedLoginMethod::Chatgpt, AuthMode::Chatgpt) | (ForcedLoginMethod::Chatgpt, AuthMode::ChatgptAuthTokens) - | (ForcedLoginMethod::Chatgpt, AuthMode::CallerProvided) + | (ForcedLoginMethod::Chatgpt, AuthMode::ExternalProvided) | (ForcedLoginMethod::Chatgpt, AuthMode::AgentIdentity) | (ForcedLoginMethod::Chatgpt, AuthMode::PersonalAccessToken) => None, (ForcedLoginMethod::Api, AuthMode::Chatgpt) | (ForcedLoginMethod::Api, AuthMode::ChatgptAuthTokens) - | (ForcedLoginMethod::Api, AuthMode::CallerProvided) + | (ForcedLoginMethod::Api, AuthMode::ExternalProvided) | (ForcedLoginMethod::Api, AuthMode::AgentIdentity) | (ForcedLoginMethod::Api, AuthMode::PersonalAccessToken) => Some( "API key login is required, but ChatGPT is currently being used. Logging out." @@ -1149,7 +1147,7 @@ async fn enforce_login_restrictions_with_agent_identity_authapi_base_url( if let Some(expected_account_ids) = config.forced_chatgpt_workspace_id.as_deref() { let chatgpt_account_id = match &auth { CodexAuth::ApiKey(_) | CodexAuth::BedrockApiKey(_) => return Ok(()), - CodexAuth::CallerProvided(_) + CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) => auth.get_account_id(), CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) => { @@ -1868,7 +1866,7 @@ pub trait AuthManagerConfig { /// Returns in-memory auth supplied by a trusted embedding runtime. /// /// Implementations must not populate this from user-controlled config. - fn caller_provided_auth(&self) -> Option { + fn external_provided_auth(&self) -> Option { None } } @@ -2213,7 +2211,7 @@ impl AuthManager { | (AuthMode::ChatgptAuthTokens, AuthMode::ChatgptAuthTokens) => { a.get_current_auth_json() == b.get_current_auth_json() } - (AuthMode::CallerProvided, AuthMode::CallerProvided) => a == b, + (AuthMode::ExternalProvided, AuthMode::ExternalProvided) => a == b, (AuthMode::AgentIdentity, AuthMode::AgentIdentity) => match (a, b) { (CodexAuth::AgentIdentity(a), CodexAuth::AgentIdentity(b)) => { a.record() == b.record() @@ -2298,9 +2296,9 @@ impl AuthManager { } } - /// Replaces the current auth snapshot with auth supplied by the caller. - pub fn set_caller_provided_auth(&self, auth: CallerProvidedAuth) { - let _ = self.set_cached_auth(Some(CodexAuth::CallerProvided(auth))); + /// Replaces the current auth snapshot with externally provided auth. + pub fn set_external_provided_auth(&self, auth: ExternalProvidedAuth) { + let _ = self.set_cached_auth(Some(CodexAuth::ExternalProvided(auth))); } pub fn clear_external_auth(&self) { @@ -2377,8 +2375,8 @@ impl AuthManager { config.auth_route_config(), ) .await; - if let Some(auth) = config.caller_provided_auth() { - auth_manager.set_caller_provided_auth(auth); + if let Some(auth) = config.external_provided_auth() { + auth_manager.set_external_provided_auth(auth); } auth_manager } @@ -2503,7 +2501,7 @@ impl AuthManager { .await } CodexAuth::ApiKey(_) - | CodexAuth::CallerProvided(_) + | CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) | CodexAuth::BedrockApiKey(_) => Ok(()), @@ -2565,8 +2563,12 @@ impl AuthManager { } pub fn current_auth_uses_codex_backend(&self) -> bool { - self.get_api_auth_mode() - .is_some_and(AuthMode::uses_codex_backend) + if self.has_external_api_key_auth() { + return false; + } + self.auth_cached() + .as_ref() + .is_some_and(CodexAuth::uses_codex_backend) } fn should_refresh_proactively(auth: &CodexAuth) -> bool { diff --git a/codex-rs/login/src/auth/mod.rs b/codex-rs/login/src/auth/mod.rs index 1953ec6110..ccf5525336 100644 --- a/codex-rs/login/src/auth/mod.rs +++ b/codex-rs/login/src/auth/mod.rs @@ -7,15 +7,15 @@ mod personal_access_token; mod storage; mod util; -mod caller_provided; mod external_bearer; +mod external_provided; mod manager; mod revoke; pub use bedrock_api_key::BedrockApiKeyAuth; pub use bedrock_api_key::login_with_bedrock_api_key; -pub use caller_provided::CallerProvidedAuth; -pub use caller_provided::CallerProvidedAuthCapabilities; pub use error::RefreshTokenFailedError; pub use error::RefreshTokenFailedReason; +pub use external_provided::ExternalProvidedAuth; +pub use external_provided::ExternalProvidedAuthCapabilities; pub use manager::*; diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index ed188c4fb9..0e824069b9 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -28,8 +28,6 @@ pub use auth::CLIENT_ID; pub use auth::CLIENT_ID_OVERRIDE_ENV_VAR; pub use auth::CODEX_ACCESS_TOKEN_ENV_VAR; pub use auth::CODEX_API_KEY_ENV_VAR; -pub use auth::CallerProvidedAuth; -pub use auth::CallerProvidedAuthCapabilities; pub use auth::CodexAuth; pub use auth::ExternalAuth; pub use auth::ExternalAuthChatgptMetadata; @@ -37,6 +35,8 @@ pub use auth::ExternalAuthFuture; pub use auth::ExternalAuthRefreshContext; pub use auth::ExternalAuthRefreshReason; pub use auth::ExternalAuthTokens; +pub use auth::ExternalProvidedAuth; +pub use auth::ExternalProvidedAuthCapabilities; 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; diff --git a/codex-rs/model-provider-info/src/lib.rs b/codex-rs/model-provider-info/src/lib.rs index cfe4d2c547..8f0c4446d3 100644 --- a/codex-rs/model-provider-info/src/lib.rs +++ b/codex-rs/model-provider-info/src/lib.rs @@ -244,7 +244,7 @@ impl ModelProviderInfo { Some( AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens - | AuthMode::CallerProvided + | AuthMode::ExternalProvided | AuthMode::AgentIdentity | AuthMode::PersonalAccessToken ) diff --git a/codex-rs/model-provider/src/amazon_bedrock/mod.rs b/codex-rs/model-provider/src/amazon_bedrock/mod.rs index fb5f53a945..5a24004813 100644 --- a/codex-rs/model-provider/src/amazon_bedrock/mod.rs +++ b/codex-rs/model-provider/src/amazon_bedrock/mod.rs @@ -69,7 +69,7 @@ impl AmazonBedrockModelProvider { CodexAuth::ApiKey(_) | CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) - | CodexAuth::CallerProvided(_) + | CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) => None, }) diff --git a/codex-rs/model-provider/src/auth.rs b/codex-rs/model-provider/src/auth.rs index cadb8e5388..25b375db55 100644 --- a/codex-rs/model-provider/src/auth.rs +++ b/codex-rs/model-provider/src/auth.rs @@ -8,8 +8,8 @@ use codex_api::AgentIdentityTelemetry; use codex_api::AuthProvider; use codex_api::SharedAuthProvider; use codex_login::AuthManager; -use codex_login::CallerProvidedAuth; use codex_login::CodexAuth; +use codex_login::ExternalProvidedAuth; use codex_login::auth::AgentIdentityAuth; use codex_login::auth::AgentIdentityAuthError; use codex_login::auth::AgentIdentityAuthPolicy; @@ -112,11 +112,11 @@ impl AuthProvider for AgentIdentityAuthProvider { } #[derive(Clone, Debug)] -struct CallerProvidedAuthProvider { - auth: CallerProvidedAuth, +struct ExternalProvidedAuthProvider { + auth: ExternalProvidedAuth, } -impl AuthProvider for CallerProvidedAuthProvider { +impl AuthProvider for ExternalProvidedAuthProvider { fn add_auth_headers(&self, headers: &mut HeaderMap) { for (name, value) in self.auth.headers() { let Ok(name) = HeaderName::from_bytes(name.as_bytes()) else { @@ -266,8 +266,8 @@ fn bearer_auth_for_provider( /// Builds request-header auth for a first-party Codex auth snapshot. pub fn auth_provider_from_auth(auth: &CodexAuth) -> SharedAuthProvider { match auth { - CodexAuth::CallerProvided(auth) => { - Arc::new(CallerProvidedAuthProvider { auth: auth.clone() }) + CodexAuth::ExternalProvided(auth) => { + Arc::new(ExternalProvidedAuthProvider { auth: auth.clone() }) } CodexAuth::AgentIdentity(auth) => { Arc::new(AgentIdentityAuthProvider { auth: auth.clone() }) @@ -435,9 +435,9 @@ mod tests { } #[test] - fn caller_provided_auth_provider_uses_caller_headers() { - let auth = CodexAuth::CallerProvided( - CallerProvidedAuth::new( + fn external_provided_auth_provider_uses_caller_headers() { + let auth = CodexAuth::ExternalProvided( + ExternalProvidedAuth::new( [( "x-openai-actor-authorization".to_string(), "actor-token".to_string(), diff --git a/codex-rs/model-provider/src/provider.rs b/codex-rs/model-provider/src/provider.rs index 23c9dd0926..13e93be724 100644 --- a/codex-rs/model-provider/src/provider.rs +++ b/codex-rs/model-provider/src/provider.rs @@ -286,7 +286,7 @@ impl ModelProvider for ConfiguredModelProvider { } CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) - | CodexAuth::CallerProvided(_) + | CodexAuth::ExternalProvided(_) | CodexAuth::AgentIdentity(_) | CodexAuth::PersonalAccessToken(_) => { let email = auth.get_account_email(); diff --git a/codex-rs/otel/src/lib.rs b/codex-rs/otel/src/lib.rs index 217695901a..31bb0fae0a 100644 --- a/codex-rs/otel/src/lib.rs +++ b/codex-rs/otel/src/lib.rs @@ -59,7 +59,7 @@ impl From for TelemetryAuthMode { AuthMode::ApiKey | AuthMode::BedrockApiKey => Self::ApiKey, AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens - | AuthMode::CallerProvided + | AuthMode::ExternalProvided | AuthMode::AgentIdentity | AuthMode::PersonalAccessToken => Self::Chatgpt, } diff --git a/codex-rs/protocol/src/auth.rs b/codex-rs/protocol/src/auth.rs index 85d2725471..ae4cb9f0cf 100644 --- a/codex-rs/protocol/src/auth.rs +++ b/codex-rs/protocol/src/auth.rs @@ -18,9 +18,9 @@ pub enum AuthMode { /// Backend auth supplied programmatically by the caller. /// /// Request headers are kept in memory and are not persisted or refreshed by Codex. - #[serde(rename = "callerProvided")] - #[strum(serialize = "callerProvided")] - CallerProvided, + #[serde(rename = "externalProvided")] + #[strum(serialize = "externalProvided")] + ExternalProvided, /// Programmatic Codex auth backed by a registered Agent Identity. #[serde(rename = "agentIdentity")] #[strum(serialize = "agentIdentity")] @@ -37,10 +37,13 @@ pub enum AuthMode { impl AuthMode { /// Returns whether this mode represents an authenticated human ChatGPT account. + /// + /// Externally provided auth configures this capability per auth instance, + /// so the mode alone cannot assert it. pub fn has_chatgpt_account(self) -> bool { match self { Self::Chatgpt | Self::ChatgptAuthTokens | Self::PersonalAccessToken => true, - Self::ApiKey | Self::CallerProvided | Self::AgentIdentity | Self::BedrockApiKey => { + Self::ApiKey | Self::ExternalProvided | Self::AgentIdentity | Self::BedrockApiKey => { false } } @@ -48,7 +51,7 @@ impl AuthMode { /// Returns whether this mode is backed by Codex services rather than a direct model API. /// - /// Caller-provided auth configures this capability per auth instance, so + /// Externally provided auth configures this capability per auth instance, so /// the mode alone cannot assert it. pub fn uses_codex_backend(self) -> bool { match self { @@ -56,7 +59,7 @@ impl AuthMode { | Self::ChatgptAuthTokens | Self::AgentIdentity | Self::PersonalAccessToken => true, - Self::ApiKey | Self::CallerProvided | Self::BedrockApiKey => false, + Self::ApiKey | Self::ExternalProvided | Self::BedrockApiKey => false, } } } diff --git a/codex-rs/tui/src/app/app_server_events.rs b/codex-rs/tui/src/app/app_server_events.rs index 36c61561f0..6dbc20aaab 100644 --- a/codex-rs/tui/src/app/app_server_events.rs +++ b/codex-rs/tui/src/app/app_server_events.rs @@ -86,7 +86,7 @@ impl App { Some( AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens - | AuthMode::CallerProvided + | AuthMode::ExternalProvided | AuthMode::AgentIdentity | AuthMode::PersonalAccessToken ) diff --git a/codex-rs/tui/src/app_server_session.rs b/codex-rs/tui/src/app_server_session.rs index f424f419f7..ea4275116b 100644 --- a/codex-rs/tui/src/app_server_session.rs +++ b/codex-rs/tui/src/app_server_session.rs @@ -1202,7 +1202,7 @@ pub(crate) fn status_account_display_from_auth_mode( Some(AuthMode::ApiKey) => Some(StatusAccountDisplay::ApiKey), Some(AuthMode::Chatgpt) | Some(AuthMode::ChatgptAuthTokens) - | Some(AuthMode::CallerProvided) + | Some(AuthMode::ExternalProvided) | Some(AuthMode::AgentIdentity) | Some(AuthMode::PersonalAccessToken) => Some(StatusAccountDisplay::ChatGpt { email: None, diff --git a/codex-rs/tui/src/onboarding/auth.rs b/codex-rs/tui/src/onboarding/auth.rs index f44ccc9170..9a6b46e228 100644 --- a/codex-rs/tui/src/onboarding/auth.rs +++ b/codex-rs/tui/src/onboarding/auth.rs @@ -950,7 +950,7 @@ impl AuthModeWidget { ApiAuthMode::ApiKey => AuthMode::ApiKey, ApiAuthMode::Chatgpt => AuthMode::Chatgpt, ApiAuthMode::ChatgptAuthTokens => AuthMode::ChatgptAuthTokens, - ApiAuthMode::CallerProvided => AuthMode::CallerProvided, + ApiAuthMode::ExternalProvided => AuthMode::ExternalProvided, ApiAuthMode::AgentIdentity => AuthMode::AgentIdentity, ApiAuthMode::PersonalAccessToken => AuthMode::PersonalAccessToken, ApiAuthMode::BedrockApiKey => AuthMode::BedrockApiKey,