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.
Trait Implementations§
Source§impl Clone for CodexCredentials
impl Clone for CodexCredentials
Source§impl Debug for CodexCredentials
impl Debug for CodexCredentials
Source§impl<'de> Deserialize<'de> for CodexCredentials
impl<'de> Deserialize<'de> for CodexCredentials
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CodexCredentials
impl RefUnwindSafe for CodexCredentials
impl Send for CodexCredentials
impl Sync for CodexCredentials
impl Unpin for CodexCredentials
impl UnsafeUnpin for CodexCredentials
impl UnwindSafe for CodexCredentials
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more