A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
fix(codex): accept Codex CLI bookkeeping keys in managed auth tokens
Jasonefe1dd2aa1d7
diff --git a/src-tauri/src/codex_config.rs b/src-tauri/src/codex_config.rsindex dfd6230fb..d6439e37a 100644--- a/src-tauri/src/codex_config.rs+++ b/src-tauri/src/codex_config.rs@@ -306,7 +306,7 @@ pub(crate) fn codex_managed_oauth_live_auth_marker_exists() -> bool {////// 仅接受 ChatGPT 登录形状(`auth_mode == "chatgpt"`、`OPENAI_API_KEY` 可清空)。/// 托管账号写入的完整 bundle 会额外带 `tokens.refresh_token` 与顶层 `last_refresh`,-/// 这里一并容忍。Codex CLI 自刷新会轮换 access_token,因此短期 token 指纹不能+/// 这里一并容忍;`tokens` 下其余由 Codex CLI 写入的键也不影响判定。Codex CLI 自刷新会轮换 access_token,因此短期 token 指纹不能/// 作为稳定的所有权谓词;cc-switch 的本地账号 ID 单独记录在 marker 中。fn extract_codex_managed_oauth_account_id(auth: &Value) -> Option<String> {let auth_obj = auth.as_object()?;@@ -331,17 +331,11 @@ fn extract_codex_managed_oauth_account_id(auth: &Value) -> Option<String> {return None;}+ // `tokens` 里多出的键不作数:Codex CLI 0.172 自刷新时会写入 `login_owner_id`、+ // `oauth_provenance` 这类簿记字段。所有权由 marker 里的 workspace ID + id_token+ // 用户身份判定,不靠这里的键集合。let tokens = auth.get("tokens").and_then(|value| value.as_object())?;- if tokens.keys().any(|key| {- !matches!(- key.as_str(),- "access_token" | "account_id" | "id_token" | "refresh_token"- )- }) {- return None;- }-let account_id = tokens.get("account_id").and_then(|value| value.as_str())diff --git a/src-tauri/src/codex_config/tests.rs b/src-tauri/src/codex_config/tests.rsindex 163f0e765..c7bebbdf6 100644--- a/src-tauri/src/codex_config/tests.rs+++ b/src-tauri/src/codex_config/tests.rs@@ -266,6 +266,18 @@ fn managed_chatgpt_login_matches_local_marker_and_workspace() {!codex_live_auth_matches_managed_request("local-account-a", "other-access").unwrap(),"another user's bearer in the same workspace must not match");+ // Codex CLI 0.172 自刷新会往 tokens 里加簿记字段,同一个账号仍须认出来 (#10157)。+ let mut cli_refreshed = full_bundle.clone();+ cli_refreshed["tokens"]["login_owner_id"] = json!("owner");+ cli_refreshed["tokens"]["oauth_provenance"] = json!("codex-cli");+ crate::config::write_json_file(&get_codex_auth_path(), &cli_refreshed)+ .expect("write CLI-refreshed live auth");+ assert!(+ codex_live_auth_matches_managed_request("local-account-a", "access").unwrap(),+ "extra Codex CLI bookkeeping keys in tokens must not break ownership"+ );+ crate::config::write_json_file(&get_codex_auth_path(), &full_bundle)+ .expect("restore managed live auth");let managed_id_token = full_bundle.pointer("/tokens/id_token").and_then(Value::as_str)