diff --git a/codex-rs/login/src/auth.rs b/codex-rs/login/src/auth.rs index 8ca2d24ca2..e7ddc0853d 100644 --- a/codex-rs/login/src/auth.rs +++ b/codex-rs/login/src/auth.rs @@ -5,10 +5,10 @@ use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; +use crate::auth_store::AuthDotJson; use crate::auth_store::get_auth_file; use crate::auth_store::try_read_auth_json; use crate::auth_store::update_tokens; -use crate::auth_store::AuthDotJson; use crate::refresh::try_refresh_token; use crate::token_data::TokenData; @@ -146,7 +146,10 @@ impl CodexAuth { } } -pub(crate) fn load_auth(codex_home: &Path, include_env_var: bool) -> std::io::Result> { +pub(crate) fn load_auth( + codex_home: &Path, + include_env_var: bool, +) -> std::io::Result> { // First, check to see if there is a valid auth.json file. If not, we fall // back to AuthMode::ApiKey using the OPENAI_API_KEY environment variable // (if it is set). @@ -217,5 +220,3 @@ fn read_openai_api_key_from_env() -> Option { .ok() .filter(|s| !s.is_empty()) } - - diff --git a/codex-rs/login/src/auth_store.rs b/codex-rs/login/src/auth_store.rs index 73e7103cd7..11877a16af 100644 --- a/codex-rs/login/src/auth_store.rs +++ b/codex-rs/login/src/auth_store.rs @@ -95,9 +95,8 @@ pub(crate) fn update_tokens( if let Some(r) = refresh_token { obj["tokens"]["refresh_token"] = serde_json::Value::String(r); } - obj["last_refresh"] = serde_json::Value::String( - Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Micros, true), - ); + obj["last_refresh"] = + serde_json::Value::String(Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Micros, true)); let updated = serde_json::to_string_pretty(&obj)?; std::fs::write(auth_file, updated)?; // Return parsed structure @@ -139,5 +138,3 @@ pub(crate) fn write_new_auth_json( file.write_all(contents.as_bytes())?; file.flush() } - - diff --git a/codex-rs/login/src/entrypoints.rs b/codex-rs/login/src/entrypoints.rs index 1b4c3adf2e..4e56c7e41b 100644 --- a/codex-rs/login/src/entrypoints.rs +++ b/codex-rs/login/src/entrypoints.rs @@ -102,5 +102,3 @@ pub async fn login_with_chatgpt( .map_err(|e| std::io::Error::other(format!("task join error: {e}")))??; Ok(()) } - - diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index 99b6ca0cf0..1d5a289259 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -11,11 +11,11 @@ mod token_data; pub use auth::AuthMode; pub use auth::CodexAuth; +pub use auth_store::AuthDotJson; pub use auth_store::get_auth_file; pub use auth_store::login_with_api_key; pub use auth_store::logout; pub use auth_store::try_read_auth_json; -pub use auth_store::AuthDotJson; pub use entrypoints::SpawnedLogin; pub use entrypoints::login_with_chatgpt; pub use entrypoints::spawn_login_with_chatgpt; @@ -31,5 +31,3 @@ pub const EXIT_CODE_WHEN_ADDRESS_ALREADY_IN_USE: i32 = 13; #[cfg(test)] mod lib_tests; - - diff --git a/codex-rs/login/src/lib_tests.rs b/codex-rs/login/src/lib_tests.rs index 2d8a28be6b..5dcc71b333 100644 --- a/codex-rs/login/src/lib_tests.rs +++ b/codex-rs/login/src/lib_tests.rs @@ -3,9 +3,9 @@ use super::*; use crate::auth::AuthMode; use crate::auth::CodexAuth; use crate::auth::load_auth; +use crate::auth_store::AuthDotJson; use crate::auth_store::get_auth_file; use crate::auth_store::logout; -use crate::auth_store::AuthDotJson; use crate::token_data::IdTokenInfo; use crate::token_data::KnownPlan; use crate::token_data::PlanType; @@ -14,8 +14,8 @@ use base64::Engine; use pretty_assertions::assert_eq; use serde::Serialize; use serde_json::json; -use tempfile::tempdir; use std::path::Path; +use tempfile::tempdir; const LAST_REFRESH: &str = "2025-08-06T20:41:36.232376Z"; @@ -172,7 +172,10 @@ fn write_auth_file(params: AuthFileParams, codex_home: &Path) -> std::io::Result alg: &'static str, typ: &'static str, } - let header = Header { alg: "none", typ: "JWT" }; + let header = Header { + alg: "none", + typ: "JWT", + }; let payload = serde_json::json!({ "email": "user@example.com", "email_verified": true, @@ -252,5 +255,3 @@ fn logout_removes_auth_file() -> Result<(), std::io::Error> { assert!(!dir.path().join("auth.json").exists()); Ok(()) } - - diff --git a/codex-rs/login/src/refresh.rs b/codex-rs/login/src/refresh.rs index f710036ae5..d5d1f5cf62 100644 --- a/codex-rs/login/src/refresh.rs +++ b/codex-rs/login/src/refresh.rs @@ -46,5 +46,3 @@ pub(crate) async fn try_refresh_token(refresh_token: String) -> std::io::Result< ))) } } - - diff --git a/codex-rs/login/src/server.rs b/codex-rs/login/src/server.rs index cb005f63c4..f077a5df12 100644 --- a/codex-rs/login/src/server.rs +++ b/codex-rs/login/src/server.rs @@ -1,6 +1,7 @@ // use rand::RngCore; use reqwest::blocking::Client; +use serde_json::json; use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; @@ -10,24 +11,19 @@ use tiny_http::Header; use tiny_http::Method; use tiny_http::Response; use tiny_http::Server; -use serde_json::json; use url::Url; use url::form_urlencoded; +use crate::auth_store::write_new_auth_json; use crate::pkce::generate_pkce; use crate::success_url::build_success_url; use crate::token_data::extract_login_context_from_tokens; -use crate::auth_store::write_new_auth_json; pub const DEFAULT_PORT: u16 = 1455; pub const DEFAULT_ISSUER: &str = "https://auth.openai.com"; pub const LOGIN_SUCCESS_HTML: &str = include_str!("./success_page.html"); -// - -// - #[derive(Debug, Clone)] pub struct LoginServerOptions { pub codex_home: PathBuf, @@ -37,19 +33,11 @@ pub struct LoginServerOptions { pub open_browser: bool, pub redeem_credits: bool, pub expose_state_endpoint: bool, - /// When set, the server will auto-exit after the specified number of seconds by - /// issuing an internal request to a test-only endpoint. Intended for CI/tests. + /// timeout after x secs for e2e tests pub testing_timeout_secs: Option, pub verbose: bool, } -/// Extracts commonly used claims from ID and access tokens. -/// - account_id is taken from the ID token. -/// - org_id/project_id prefer ID token, falling back to access token. -/// - plan_type comes from the access token. -/// - needs_setup is computed from (completed_platform_onboarding, is_org_owner) -/// with the same precedence as org/project. - // Only default issuer supported for platform/api bases const PLATFORM_BASE: &str = "https://platform.openai.com"; const API_BASE: &str = "https://api.openai.com"; diff --git a/codex-rs/login/src/token_data.rs b/codex-rs/login/src/token_data.rs index 11962ab222..46d5f9cb84 100644 --- a/codex-rs/login/src/token_data.rs +++ b/codex-rs/login/src/token_data.rs @@ -166,17 +166,18 @@ fn decode_jwt_payload(token: &str) -> Option> { let _header = parts.next(); let payload_b64 = parts.next(); let _sig = parts.next(); - payload_b64.and_then(|p| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(p).ok()) + payload_b64.and_then(|p| { + base64::engine::general_purpose::URL_SAFE_NO_PAD + .decode(p) + .ok() + }) } fn parse_auth_inner_claims(token: &str) -> AuthInnerClaims { - match decode_jwt_payload(token) + decode_jwt_payload(token) .and_then(|bytes| serde_json::from_slice::(&bytes).ok()) .and_then(|o| o.auth) - { - Some(inner) => inner, - None => AuthInnerClaims::default(), - } + .unwrap_or_default() } /// Extracts commonly used claims from ID and access tokens. diff --git a/codex-rs/login/tests/server.rs b/codex-rs/login/tests/server.rs index 709950fe83..d9115c4da6 100644 --- a/codex-rs/login/tests/server.rs +++ b/codex-rs/login/tests/server.rs @@ -249,9 +249,8 @@ fn start_mock_oauth_server(port: u16, behavior: MockBehavior) { .with_status_code(500), ); } - } - // Old token-exchange fallback behavior removed - // Old token-exchange fallback behavior removed + } // Old token-exchange fallback behavior removed + // Old token-exchange fallback behavior removed } } else if request.method() == &tiny_http::Method::Post && url.starts_with("/v1/billing/redeem_credits")