#[non_exhaustive]pub struct OAuthCredential {
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_at_ms: i64,
pub subscription_type: Option<String>,
pub scopes: Vec<String>,
}Expand description
A refreshable OAuth credential read from / written to the
claude CLI’s credential file.
Field naming mirrors the on-disk JSON exactly so deserialization
stays a one-line serde_json::from_slice. #[non_exhaustive]
closes off direct struct-literal construction so future
server-returned fields ship as additive minor releases — use
OAuthCredential::new plus the with_* chain.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.access_token: StringBearer token forwarded to Anthropic in the Authorization
header.
refresh_token: Option<String>Long-lived refresh token. None means the credential cannot
renew itself once the access token expires.
expires_at_ms: i64Unix-millis epoch at which the access token expires.
subscription_type: Option<String>pro / team / etc. — informational, not load-bearing for
transport. Preserved across refresh so storage round-trips
keep the original metadata.
scopes: Vec<String>OAuth scopes granted to this token. Preserved across refresh.
Implementations§
Source§impl OAuthCredential
impl OAuthCredential
Sourcepub fn new(access_token: impl Into<String>, expires_at_ms: i64) -> Self
pub fn new(access_token: impl Into<String>, expires_at_ms: i64) -> Self
Construct a credential from the two mandatory fields. Use
the with_* chain for the optional ones.
Sourcepub fn with_refresh_token(self, token: impl Into<String>) -> Self
pub fn with_refresh_token(self, token: impl Into<String>) -> Self
Set the long-lived refresh token.
Sourcepub fn with_subscription_type(self, tier: impl Into<String>) -> Self
pub fn with_subscription_type(self, tier: impl Into<String>) -> Self
Set the subscription tier (pro / team / …).
Sourcepub fn with_scopes<I, S>(self, scopes: I) -> Self
pub fn with_scopes<I, S>(self, scopes: I) -> Self
Replace the granted-scopes list.
Sourcepub fn expires_at(&self) -> Option<DateTime<Utc>>
pub fn expires_at(&self) -> Option<DateTime<Utc>>
Wall-clock instant the access token expires, or None when
expires_at_ms does not represent a valid Unix-millis epoch
(storage corruption / server bug). Surfaces the loss
explicitly rather than coercing to “now” — the credential
is then treated as already expired by Self::needs_refresh.
Sourcepub fn needs_refresh(&self) -> bool
pub fn needs_refresh(&self) -> bool
True when the access token is past its expiry — resolve
must trigger a refresh before handing the token to a
transport. An unrepresentable expires_at_ms (storage
corruption, server bug) reads as already-expired so the
provider refreshes rather than handing out a stale token.
Includes a 60-second skew window so a token about to expire
mid-flight refreshes proactively.
Sourcepub fn to_bearer_secret(&self) -> SecretString
pub fn to_bearer_secret(&self) -> SecretString
Wrap the access token in a SecretString formatted as
Bearer <token> for transport use. Allocates a fresh secret
per call so callers can hand it straight to
entelix_core::auth::Credentials::header_value.
Trait Implementations§
Source§impl Clone for OAuthCredential
impl Clone for OAuthCredential
Source§fn clone(&self) -> OAuthCredential
fn clone(&self) -> OAuthCredential
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more