[codex] Add externally provided Codex auth (#31274)

## Summary

Add an in-memory externally provided Codex auth snapshot with explicit
runtime capabilities, installed through the existing `ExternalAuth`
provider path.

## Testing

- `just fmt-check`
- `cargo test -p codex-login --lib externally_provided_auth`
- `cargo test -p codex-core --lib
external_auth_snapshot_is_installed_from_runtime_config`
- `cargo test -p codex-model-provider --lib external_auth`
- `cargo test -p codex-mcp-extension --test hosted_apps_mcp
hosted_apps_mcp_accepts_external_provided_codex_auth`
- `cargo check -p codex-app-server -p codex-core-api -p
codex-thread-manager-sample`

---------

Co-authored-by: pakrym-oai <pakrym@openai.com>
This commit is contained in:
lt-oaiandpakrym-oai authored and GitHub committed 2026-07-07 17:43:19 -07:00
1 parent dbd2df27d1
commit 8784de445e
29 files changed
+278 -7

No files matched your search

+55
View File
@@ -1093,6 +1093,61 @@ async fn unauthorized_recovery_uses_external_refresh_for_bearer_manager() {
assert_eq!(refreshed_token.as_deref(), Some("refreshed-provider-token"));
}
#[derive(Clone)]
struct StaticExternalAuth(CodexAuth);
impl ExternalAuth for StaticExternalAuth {
fn resolve(&self) -> ExternalAuthFuture<'_, CodexAuth> {
Box::pin(async { Ok(self.0.clone()) })
}
fn refresh(&self, _context: ExternalAuthRefreshContext) -> ExternalAuthFuture<'_, CodexAuth> {
Box::pin(async { Ok(self.0.clone()) })
}
}
#[tokio::test]
async fn external_auth_provider_can_install_headers() {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
reqwest::header::AUTHORIZATION,
reqwest::header::HeaderValue::from_static("Bearer external"),
);
headers.insert(
"x-external-auth",
reqwest::header::HeaderValue::from_static("enabled"),
);
let auth = CodexAuth::Headers(AuthHeaders::new(headers));
let codex_home = tempdir().expect("tempdir");
let manager = AuthManager::new(
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::Ephemeral,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
/*auth_route_config*/ None,
)
.await;
manager
.set_external_auth(Arc::new(StaticExternalAuth(auth.clone())))
.await
.expect("external auth should install");
assert_eq!(manager.auth_cached(), Some(auth));
assert!(
manager
.auth_cached()
.is_some_and(|auth| auth.uses_codex_backend())
);
assert!(
!manager
.auth_cached()
.is_some_and(|auth| auth.is_chatgpt_auth())
);
}
struct ProviderAuthScript {
tempdir: TempDir,
command: String,