pub struct Token { /* private fields */ }Expand description
A bearer token, shared behind one pointer so that it stays cheap to clone and embed.
Implementations§
Source§impl Token
impl Token
Sourcepub fn expose_secret(&self) -> &str
pub fn expose_secret(&self) -> &str
The token itself, to send as a bearer credential or store.
Sourcepub fn resource(&self) -> Option<&str>
pub fn resource(&self) -> Option<&str>
The resource the token is for, such as the API URL to call, when its token response named one. Clients read this rather than the token’s claims (RFC 9068 §6).
Sourcepub fn with_resource(self, resource: Option<String>) -> Self
pub fn with_resource(self, resource: Option<String>) -> Self
Record the resource that the token’s response named.
Sourcepub fn unverified_claims<T: DeserializeOwned>(&self) -> CredentialResult<T>
pub fn unverified_claims<T: DeserializeOwned>(&self) -> CredentialResult<T>
Decode the claims of a JWT without verifying its signature.
Use the claims only to manage the token, such as deciding when to refresh it; the service that accepts the token is the one that verifies it.
Sourcepub fn remaining_lifetime(&self) -> CredentialResult<Duration>
pub fn remaining_lifetime(&self) -> CredentialResult<Duration>
How long until the token expires, without validating its signature.
Zero once expired, rather than underflowing.
Sourcepub fn is_expired(&self) -> CredentialResult<bool>
pub fn is_expired(&self) -> CredentialResult<bool>
True if the token has expired or will within 30 seconds. Such a token is unusable.
Sourcepub fn needs_refresh(&self) -> CredentialResult<bool>
pub fn needs_refresh(&self) -> CredentialResult<bool>
True if the token expires within a minute. It is still usable, but a fresh one should be fetched proactively.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnsafeUnpin for Token
impl UnwindSafe for Token
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
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.