From 8e906caadd654aec274c531102bc1fcfd3a7c584 Mon Sep 17 00:00:00 2001 From: canvrno-oai Date: Wed, 27 May 2026 16:20:06 -0700 Subject: [PATCH] simplify --- .../request_processors/account_processor.rs | 3 +-- codex-rs/cli/src/login.rs | 14 ++++++------ codex-rs/login/src/auth/default_client.rs | 22 +++++++++++++++---- codex-rs/login/src/device_code_auth.rs | 11 +++------- codex-rs/login/src/server.rs | 22 ++++++------------- 5 files changed, 36 insertions(+), 36 deletions(-) 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 c34122376c..4085ae6989 100644 --- a/codex-rs/app-server/src/request_processors/account_processor.rs +++ b/codex-rs/app-server/src/request_processors/account_processor.rs @@ -326,9 +326,8 @@ impl AccountRequestProcessor { config.forced_chatgpt_workspace_id.clone(), config.cli_auth_credentials_store_mode, ) + .with_network_config(config.network.as_ref()) }; - let mut opts = opts; - opts.set_network_config(config.network.as_ref()); #[cfg(debug_assertions)] let opts = { let mut opts = opts; diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rs index 2c70d82968..0872abc29f 100644 --- a/codex-rs/cli/src/login.rs +++ b/codex-rs/cli/src/login.rs @@ -119,13 +119,13 @@ pub async fn login_with_chatgpt( cli_auth_credentials_store_mode: AuthCredentialsStoreMode, network: Option<&codex_config::types::NetworkConfigToml>, ) -> std::io::Result<()> { - let mut opts = ServerOptions::new( + let opts = ServerOptions::new( codex_home, CLIENT_ID.to_string(), forced_chatgpt_workspace_id, cli_auth_credentials_store_mode, - ); - opts.set_network_config(network); + ) + .with_network_config(network); let server = run_login_server(opts)?; print_login_server_start(server.actual_port, &server.auth_url); @@ -285,8 +285,8 @@ pub async fn run_login_with_device_code( client_id.unwrap_or(CLIENT_ID.to_string()), forced_chatgpt_workspace_id, config.cli_auth_credentials_store_mode, - ); - opts.set_network_config(config.network.as_ref()); + ) + .with_network_config(config.network.as_ref()); if let Some(iss) = issuer_base_url { opts.issuer = iss; } @@ -325,8 +325,8 @@ pub async fn run_login_with_device_code_fallback_to_browser( client_id.unwrap_or(CLIENT_ID.to_string()), forced_chatgpt_workspace_id, config.cli_auth_credentials_store_mode, - ); - opts.set_network_config(config.network.as_ref()); + ) + .with_network_config(config.network.as_ref()); if let Some(iss) = issuer_base_url { opts.issuer = iss; } diff --git a/codex-rs/login/src/auth/default_client.rs b/codex-rs/login/src/auth/default_client.rs index d6bdfef791..cf3ac7ba27 100644 --- a/codex-rs/login/src/auth/default_client.rs +++ b/codex-rs/login/src/auth/default_client.rs @@ -254,14 +254,28 @@ pub fn try_build_reqwest_client_with_proxy_config( return build_reqwest_client_with_custom_ca(builder).map_err(Into::into); } - build_reqwest_client_for_route( - builder, - DEFAULT_AUTH_ROUTE_URL, - RouteTarget::Auth, + build_auth_reqwest_client_with_builder(builder, DEFAULT_AUTH_ROUTE_URL, outbound_proxy_config) +} + +pub(crate) fn build_auth_reqwest_client_with_proxy_config( + endpoint: &str, + outbound_proxy_config: Option<&OutboundProxyConfig>, +) -> Result { + build_auth_reqwest_client_with_builder( + reqwest::Client::builder(), + endpoint, outbound_proxy_config, ) } +fn build_auth_reqwest_client_with_builder( + builder: reqwest::ClientBuilder, + endpoint: &str, + outbound_proxy_config: Option<&OutboundProxyConfig>, +) -> Result { + build_reqwest_client_for_route(builder, endpoint, RouteTarget::Auth, outbound_proxy_config) +} + pub fn default_headers() -> HeaderMap { let mut headers = HeaderMap::new(); headers.insert("originator", originator().header_value); diff --git a/codex-rs/login/src/device_code_auth.rs b/codex-rs/login/src/device_code_auth.rs index da62e20f30..ebb05ee12a 100644 --- a/codex-rs/login/src/device_code_auth.rs +++ b/codex-rs/login/src/device_code_auth.rs @@ -6,10 +6,9 @@ use serde::de::{self}; use std::time::Duration; use std::time::Instant; +use crate::default_client::build_auth_reqwest_client_with_proxy_config; use crate::pkce::PkceCodes; use crate::server::ServerOptions; -use codex_client::RouteTarget; -use codex_client::build_reqwest_client_for_route; use std::io; const ANSI_BLUE: &str = "\x1b[94m"; @@ -161,10 +160,8 @@ pub async fn request_device_code(opts: &ServerOptions) -> std::io::Result) { + pub fn with_network_config(mut self, network: Option<&NetworkConfigToml>) -> Self { self.outbound_proxy_config = network.map(outbound_proxy_config_from_network_config); + self } } @@ -754,12 +754,8 @@ pub(crate) async fn exchange_code_for_tokens( let token_endpoint = format!("{}/oauth/token", issuer.trim_end_matches('/')); emit_auth_network_environment_snapshot(/*operation*/ "oauth_token_exchange"); - let client = build_reqwest_client_for_route( - reqwest::Client::builder(), - &token_endpoint, - RouteTarget::Auth, - outbound_proxy_config, - )?; + let client = + build_auth_reqwest_client_with_proxy_config(&token_endpoint, outbound_proxy_config)?; info!( issuer = %sanitize_url_for_logging(issuer), token_endpoint = %sanitize_url_for_logging(&token_endpoint), @@ -1169,12 +1165,8 @@ pub(crate) async fn obtain_api_key( } let token_endpoint = format!("{}/oauth/token", issuer.trim_end_matches('/')); emit_auth_network_environment_snapshot(/*operation*/ "api_key_exchange"); - let client = build_reqwest_client_for_route( - reqwest::Client::builder(), - &token_endpoint, - RouteTarget::Auth, - outbound_proxy_config, - )?; + let client = + build_auth_reqwest_client_with_proxy_config(&token_endpoint, outbound_proxy_config)?; let resp = client .post(token_endpoint) .header("Content-Type", "application/x-www-form-urlencoded")