mirror of
https://github.com/openai/codex.git
synced 2026-04-27 16:15:09 +00:00
Refactor auth providers to mutate request headers (#17866)
## Summary - Move auth header construction into the `AuthProvider::add_auth_headers` contract. - Inline `CoreAuthProvider` header mutation in its provider impl and remove the shared header-map helper. - Update HTTP, websocket, file upload, sideband websocket, and test auth callsites to use the provider method. - Add direct coverage for `CoreAuthProvider` auth header mutation. ## Testing - `just fmt` - `cargo test -p codex-api` - `cargo test -p codex-core client::tests::auth_request_telemetry_context_tracks_attached_auth_and_retry_phase` - `cargo test -p codex-core` failed on unrelated/reproducible `tools::handlers::multi_agents::tests::multi_agent_v2_followup_task_interrupts_busy_child_without_losing_message` --------- Co-authored-by: Celia Chen <celia@openai.com>
This commit is contained in:
@@ -91,9 +91,7 @@ impl HttpTransport for RecordingTransport {
|
||||
struct NoAuth;
|
||||
|
||||
impl AuthProvider for NoAuth {
|
||||
fn bearer_token(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
fn add_auth_headers(&self, _headers: &mut HeaderMap) {}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -112,12 +110,14 @@ impl StaticAuth {
|
||||
}
|
||||
|
||||
impl AuthProvider for StaticAuth {
|
||||
fn bearer_token(&self) -> Option<String> {
|
||||
Some(self.token.clone())
|
||||
}
|
||||
|
||||
fn account_id(&self) -> Option<String> {
|
||||
Some(self.account_id.clone())
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) {
|
||||
let token = &self.token;
|
||||
if let Ok(header) = HeaderValue::from_str(&format!("Bearer {token}")) {
|
||||
headers.insert(http::header::AUTHORIZATION, header);
|
||||
}
|
||||
if let Ok(header) = HeaderValue::from_str(&self.account_id) {
|
||||
headers.insert("ChatGPT-Account-ID", header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ use wiremock::matchers::path;
|
||||
struct DummyAuth;
|
||||
|
||||
impl AuthProvider for DummyAuth {
|
||||
fn bearer_token(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
fn add_auth_headers(&self, _headers: &mut HeaderMap) {}
|
||||
}
|
||||
|
||||
fn provider(base_url: &str) -> Provider {
|
||||
|
||||
@@ -53,9 +53,7 @@ impl HttpTransport for FixtureSseTransport {
|
||||
struct NoAuth;
|
||||
|
||||
impl AuthProvider for NoAuth {
|
||||
fn bearer_token(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
fn add_auth_headers(&self, _headers: &mut HeaderMap) {}
|
||||
}
|
||||
|
||||
fn provider(name: &str) -> Provider {
|
||||
|
||||
Reference in New Issue
Block a user