pub struct CodexCredentials {
pub access_token: String,
pub refresh_token: String,
pub id_token: Option<String>,
pub account_id: Option<String>,
pub residency: Option<String>,
pub expires_at: Option<u64>,
pub earliest_refresh_at: Option<u64>,
}Expand description
Persisted ChatGPT OAuth credentials.
account_id and residency are decoded from the JWT claims of the
access/ID tokens at construction time.
Fields§
§access_token: StringShort-lived bearer token sent as Authorization.
refresh_token: StringLong-lived token for refresh_tokens; rotated on every refresh.
id_token: Option<String>OpenID ID token; a source of the account ID claim.
account_id: Option<String>ChatGPT-Account-Id header value (from JWT claims).
residency: Option<String>Optional compute-residency constraint (no_constraint means none).
expires_at: Option<u64>Access-token expiry as seconds since the Unix epoch.
earliest_refresh_at: Option<u64>Earliest time the server wants a refresh performed (epoch seconds).
Implementations§
Source§impl CodexCredentials
impl CodexCredentials
Sourcepub fn new(
access_token: impl Into<String>,
refresh_token: impl Into<String>,
) -> Self
pub fn new( access_token: impl Into<String>, refresh_token: impl Into<String>, ) -> Self
Build credentials from raw token strings, decoding account_id and
residency from the JWT claims.
Sourcepub fn with_id_token(self, id_token: impl Into<String>) -> Self
pub fn with_id_token(self, id_token: impl Into<String>) -> Self
Attach an ID token (a source of the account-ID claim) and re-decode.
Sourcepub const fn with_expires_at(self, expires_at: u64) -> Self
pub const fn with_expires_at(self, expires_at: u64) -> Self
Set the access-token expiry (seconds since the Unix epoch).
Sourcepub fn is_expired(&self, skew: Duration) -> bool
pub fn is_expired(&self, skew: Duration) -> bool
Whether the access token is expired or within skew of expiring.