mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Clarify credential storage wording across authentication UI and docs (#49361)
## Why Credentials can use a keyring backend, so describing all login and logout operations as reads or writes to `auth.json` is misleading. ## What changed - Remove the API-key onboarding claim that keys are stored in `auth.json`. - Describe authentication storage and credential-removal errors in terms of stored credentials and the selected backend. - Label the doctor output's auth-file path as the file backend or fallback, and document why startup checks also consider `config.toml` when credentials may be in a keyring. ## Testing Add API-key entry snapshots for terminal widths of 80 and 40 columns. GitOrigin-RevId: 87189f422448b88721ea2d7448930ece63102803
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
+15
@@ -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 back
|
||||
+15
@@ -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 back
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user