Files
codex/codex-rs/model-provider-info/src/oauth_session.rs
T
alexsong-oai cc2f80d515 Add file-backed storage for gateway OAuth credentials (#58219)
## What changed

Allow gateway OAuth configuration to select `credentials_store = "file"` to persist credentials in plaintext at `$CODEX_HOME/secrets/gateway_oauth.json`. Keep `keyring` as the default.

Read, update, and delete file-backed credentials by credential ID, using atomic writes and the existing cross-process lock. Preserve the serialized provider identity when using the default store.

## Testing

Add an app-server test that completes gateway OAuth login with file storage, verifies Unix file permissions are `0600`, and checks that login remains successful after a server restart.

GitOrigin-RevId: dc1d17922bd80bf65034cbc5aa3d97959e962dcc
2026-10-30 02:28:51 +00:00

42 lines
1.4 KiB
Rust

//! Public-client OAuth settings shared by managed configuration and service sign-in.
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use std::fmt;
/// Settings identifying a configured OAuth grant, independent of token delivery.
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct OAuthSessionConfig {
pub authorization_url: String,
pub token_url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub device_authorization_url: Option<String>,
pub client_id: String,
pub resource: Option<String>,
#[serde(default)]
pub scopes: Vec<String>,
pub redirect_port: Option<u16>,
/// Selected by a gateway provider. Managed config-server OAuth uses the default store.
#[serde(skip)]
pub credentials_store: OAuthCredentialsStore,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum OAuthCredentialsStore {
/// Encrypt credentials using a passphrase kept in the OS keyring.
#[default]
Keyring,
/// Store credentials in plaintext in `$CODEX_HOME/secrets/gateway_oauth.json`.
File,
}
impl fmt::Debug for OAuthSessionConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Issuer settings may contain credentials in arbitrary query parameters.
f.debug_struct("OAuthSessionConfig").finish_non_exhaustive()
}
}