mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
## Why Realtime connections bypassed runtime authentication and reused captured authentication headers for sideband handshakes. They need to honor the selected credential source and its transport policy across call creation, retries, and reconnects. ## What changed - Use runtime authentication for realtime WebSocket connections, WebRTC call creation, and sideband attachment when enabled for supported OpenAI destinations. - Resolve authentication on every WebSocket handshake, preserving credential ownership and request scope while generating fresh assertions. Reject authentication failures without falling back to bearer authentication. - Keep call creation and sideband attachment bound to the selected credentials and account network policy, including when inference uses a different provider. - Avoid runtime initialization for local marketplace and MCP operations, plugin commands that do not use the remote catalog, and model debugging with a configured catalog. ## Testing Add coverage for fresh handshake credentials on retries and reconnects, credential and account changes, runtime authentication modes, destination validation, and registration failures. GitOrigin-RevId: 57e53122912fa78a524427b0f51013f76f9f7681
67 lines
2.3 KiB
Rust
67 lines
2.3 KiB
Rust
use super::prepare_provider_request;
|
|
use crate::create_model_provider;
|
|
use crate::provider_uses_first_party_auth_path;
|
|
use base64::Engine;
|
|
use codex_login::AuthManager;
|
|
use codex_login::CodexAuth;
|
|
use codex_model_provider_info::ModelProviderInfo;
|
|
use pretty_assertions::assert_eq;
|
|
use serde_json::json;
|
|
use tempfile::TempDir;
|
|
|
|
#[tokio::test]
|
|
async fn explicit_provider_token_survives_a_workspace_switch_during_setup() {
|
|
let home = TempDir::new().unwrap();
|
|
let claims = json!({"https://api.openai.com/auth": {"chatgpt_user_id": "user-a"}});
|
|
let payload = base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(claims.to_string());
|
|
let token = format!("header.{payload}.signature");
|
|
let initial = CodexAuth::from_external_chatgpt_tokens(
|
|
&token,
|
|
"workspace-a",
|
|
/*chatgpt_plan_type*/ None,
|
|
)
|
|
.unwrap();
|
|
let manager = AuthManager::from_auth_for_testing_with_home(initial, home.path().to_path_buf());
|
|
let mut info = ModelProviderInfo::create_openai_provider(/*base_url*/ None);
|
|
info.experimental_bearer_token = Some("provider-token".into());
|
|
let provider = create_model_provider(info, Some(manager.clone()));
|
|
|
|
let mut attempts = 0;
|
|
let resolved = prepare_provider_request(
|
|
provider.as_ref(),
|
|
provider_uses_first_party_auth_path(provider.info()),
|
|
|_| {
|
|
attempts += 1;
|
|
async {
|
|
let (_, resolved) = provider.request_provider_and_auth(/*scope*/ None).await?;
|
|
codex_login::auth::login_with_chatgpt_auth_tokens(
|
|
home.path(),
|
|
&token,
|
|
"workspace-b",
|
|
/*chatgpt_plan_type*/ None,
|
|
)?;
|
|
manager.reload().await;
|
|
Ok(resolved)
|
|
}
|
|
},
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
manager.auth_cached().unwrap().get_account_id().as_deref(),
|
|
Some("workspace-b")
|
|
);
|
|
assert_eq!(attempts, 1);
|
|
let mut headers = http::HeaderMap::new();
|
|
resolved.auth.add_auth_headers(&mut headers).unwrap();
|
|
assert_eq!(
|
|
resolved.credential.as_ref().and_then(CodexAuth::api_key),
|
|
Some("provider-token")
|
|
);
|
|
assert_eq!(
|
|
headers[http::header::AUTHORIZATION],
|
|
"Bearer provider-token"
|
|
);
|
|
}
|