Lightweight coding agent that runs in your terminal
Rust
Clarify credential storage wording across authentication UI and docs (#49361)
Celia Chen94d642d8b40e
diff --git a/codex-rs/cli/src/doctor/output/detail.rs b/codex-rs/cli/src/doctor/output/detail.rsindex bca2baeaa4..d7e730c3c5 100644--- a/codex-rs/cli/src/doctor/output/detail.rs+++ b/codex-rs/cli/src/doctor/output/detail.rs@@ -750,6 +750,7 @@ fn value<'a>(parsed: &'a [ParsedDetail], label: &str) -> Option<&'a str> {fn display_label(label: &str) -> String {match label {+ "auth file" => "auth.json path (file backend/fallback)","codex-linux-sandbox helper" => "linux helper","optional reachability failed" => "optional reachability","check for update on startup" => "startup update check",diff --git a/codex-rs/login/src/auth/manager.rs b/codex-rs/login/src/auth/manager.rsindex 14cfee9221..66c20a656f 100644--- a/codex-rs/login/src/auth/manager.rs+++ b/codex-rs/login/src/auth/manager.rs@@ -976,8 +976,8 @@ fn read_non_empty_env_var(key: &str) -> Option<String> {.filter(|value| !value.is_empty())}-/// Delete the auth.json file inside `codex_home` if it exists. Returns `Ok(true)`-/// if a file was removed, `Ok(false)` if no auth file was present.+/// Delete credentials for `codex_home` through the selected storage backend.+/// Returns `Ok(true)` if credentials were removed, `Ok(false)` if none were present.pub fn logout(codex_home: &Path,auth_credentials_store_mode: AuthCredentialsStoreMode,@@ -1018,7 +1018,7 @@ pub async fn logout_with_revoke()}-/// Writes an `auth.json` that contains only the API key.+/// Store API-key credentials through the selected storage backend.pub fn login_with_api_key(codex_home: &Path,api_key: &str,@@ -1043,7 +1043,8 @@ pub fn login_with_api_key()}-/// Writes an `auth.json` that contains only the access token.+/// Validate and store personal-access-token or Agent Identity credentials through+/// the selected storage backend.pub async fn login_with_access_token(codex_home: &Path,access_token: &str,@@ -1454,7 +1455,7 @@ fn logout_with_message();let error_message = match removal_result {Ok(_) => message,- Err(err) => format!("{message}. Failed to remove auth.json: {err}"),+ Err(err) => format!("{message}. Failed to remove stored credentials: {err}"),};Err(std::io::Error::other(error_message))}@@ -2031,12 +2032,12 @@ impl UnauthorizedRecovery {}}-/// Central manager providing a single source of truth for auth.json derived+/// Central manager providing a single source of truth for stored/// authentication data. It loads once (or on preference change) and then/// hands out cloned `CodexAuth` values so the rest of the program has a/// consistent snapshot.///-/// External modifications to `auth.json` will NOT be observed until+/// External modifications to stored credentials will NOT be observed until/// `reload()` is called explicitly. This matches the design goal of avoiding/// different parts of the program seeing inconsistent auth data mid‑run.pub struct AuthManager {@@ -2939,10 +2940,10 @@ impl AuthManager {result}- /// Log out by deleting the on‑disk auth.json (if present). Returns Ok(true)- /// if a file was removed, Ok(false) if no auth file existed. On success,- /// reloads the in‑memory auth cache so callers immediately observe the- /// unauthenticated state.+ /// Log out by deleting credentials from the selected storage backend and the+ /// ephemeral store. Returns `Ok(true)` if credentials were removed, `Ok(false)`+ /// if none were present. On success, reloads the in-memory auth cache so+ /// callers immediately observe the unauthenticated state.pub async fn logout(&self) -> std::io::Result<bool> {self.ensure_logout_allowed()?;let removed = logout_all_stores(@@ -2950,7 +2951,7 @@ impl AuthManager {self.auth_credentials_store_mode,self.keyring_backend_kind,)?;- // Always reload to clear any cached auth (even if file absent).+ // Always reload to clear cached auth, even if no stored credentials were present.self.clear_external_auth();self.reload().await;Ok(removed)@@ -2970,7 +2971,7 @@ impl AuthManager {self.auth_credentials_store_mode,self.keyring_backend_kind,)?;- // Always reload to clear any cached auth (even if file absent).+ // Always reload to clear cached auth, even if no stored credentials were present.self.clear_external_auth();self.reload().await;Ok(result)diff --git a/codex-rs/tui/src/onboarding/auth.rs b/codex-rs/tui/src/onboarding/auth.rsindex 29022d525b..2cdc98ca68 100644--- a/codex-rs/tui/src/onboarding/auth.rs+++ b/codex-rs/tui/src/onboarding/auth.rs@@ -704,7 +704,7 @@ impl AuthModeWidget {"Use your own OpenAI API key for usage-based billing".bold(),]),"".into(),- " Paste or type your API key below. It will be stored locally in auth.json.".into(),+ " Paste or type your API key below.".into(),"".into(),];if state.prepopulated_from_env {@@ -1277,6 +1277,29 @@ mod tests {(widget, codex_home)}+ #[tokio::test]+ async fn api_key_entry_snapshots() {+ let (mut widget, _tmp) = widget_forced_chatgpt().await;+ widget.auth_config.forced_login_method = None;+ *widget.sign_in_state.write().unwrap() =+ SignInState::ApiKeyEntry(ApiKeyInputState::default());++ for (name, width) in [("api_key_entry", 80), ("api_key_entry_narrow", 40)] {+ let height = 14;+ let area = Rect::new(/*x*/ 0, /*y*/ 0, width, height);+ let mut terminal = crate::custom_terminal::Terminal::with_options(+ crate::test_backend::VT100Backend::new(width, height),+ )+ .expect("terminal");+ terminal.set_viewport_area(area);+ terminal+ .draw(|frame| widget.render_ref(area, frame.buffer_mut()))+ .expect("draw");++ insta::assert_snapshot!(name, terminal.backend().to_string());+ }+ }+#[tokio::test]async fn api_key_flow_disabled_when_chatgpt_forced() {let (mut widget, _tmp) = widget_forced_chatgpt().await;diff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry.snapnew file mode 100644index 0000000000..376f264c5f--- /dev/null+++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry.snap@@ -0,0 +1,15 @@+---+source: tui/src/onboarding/auth.rs+expression: terminal.backend().to_string()+---+> Use your own OpenAI API key for usage-based billing++ Paste or type your API key below.++++╭API key───────────────────────────────────────────────────────────────────────╮+│Paste or type your API key │+╰──────────────────────────────────────────────────────────────────────────────╯+ Press enter to save+ Press esc to go backdiff --git a/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry_narrow.snap b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry_narrow.snapnew file mode 100644index 0000000000..499103514f--- /dev/null+++ b/codex-rs/tui/src/onboarding/snapshots/codex_tui__onboarding__auth__tests__api_key_entry_narrow.snap@@ -0,0 +1,15 @@+---+source: tui/src/onboarding/auth.rs+expression: terminal.backend().to_string()+---+> Use your own OpenAI API key for+usage-based billing++ Paste or type your API key below.+++╭API key───────────────────────────────╮+│Paste or type your API key │+╰──────────────────────────────────────╯+ Press enter to save+ Press esc to go backdiff --git a/codex-rs/tui/src/startup_preflight.rs b/codex-rs/tui/src/startup_preflight.rsindex 7741319b76..cd284e401b 100644--- a/codex-rs/tui/src/startup_preflight.rs+++ b/codex-rs/tui/src/startup_preflight.rs@@ -45,6 +45,10 @@ pub(super) fn should_delay_startup_composer_for_first_login(match std::fs::metadata(codex_home) {Ok(metadata) if !metadata.is_dir() => return false,Ok(_) => {+ // With file auth as the default, auth.json is a hint of existing credentials.+ // An existing config.toml may select keyring storage, which need not create+ // auth.json. Keep the composer visible when any of these files exists;+ // the normal account lookup decides whether sign-in is required.for state_file in ["auth.json", "config.toml", "environments.toml"] {if !matches!(codex_home.join(state_file).try_exists(), Ok(false)) {return false;