fmt, clippy

This commit is contained in:
Eason Goodale
2025-08-08 18:18:59 -07:00
parent b668483951
commit 7c7ccdd72b
9 changed files with 26 additions and 45 deletions

View File

@@ -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<Option<CodexAuth>> {
pub(crate) fn load_auth(
codex_home: &Path,
include_env_var: bool,
) -> std::io::Result<Option<CodexAuth>> {
// 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<String> {
.ok()
.filter(|s| !s.is_empty())
}

View File

@@ -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()
}

View File

@@ -102,5 +102,3 @@ pub async fn login_with_chatgpt(
.map_err(|e| std::io::Error::other(format!("task join error: {e}")))??;
Ok(())
}

View File

@@ -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;

View File

@@ -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(())
}

View File

@@ -46,5 +46,3 @@ pub(crate) async fn try_refresh_token(refresh_token: String) -> std::io::Result<
)))
}
}

View File

@@ -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<u64>,
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";

View File

@@ -166,17 +166,18 @@ fn decode_jwt_payload(token: &str) -> Option<Vec<u8>> {
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::<AuthOuterClaims>(&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.

View File

@@ -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")