pub struct OAuth2Token { /* private fields */ }Available on crate feature
oauth2 only.Expand description
An OAuth2 access token with expiration tracking.
Implementations§
Source§impl OAuth2Token
impl OAuth2Token
Sourcepub fn with_expiry(
access_token: impl Into<String>,
expires_in: Duration,
) -> Self
pub fn with_expiry( access_token: impl Into<String>, expires_in: Duration, ) -> Self
Creates a new OAuth2 token with an expiration time.
Sourcepub fn with_refresh_token(self, refresh_token: impl Into<String>) -> Self
pub fn with_refresh_token(self, refresh_token: impl Into<String>) -> Self
Sets the refresh token.
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Returns the access token value.
Sourcepub fn refresh_token(&self) -> Option<&str>
pub fn refresh_token(&self) -> Option<&str>
Returns the refresh token if available.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if the token is expired.
Returns false if the token has no expiration time.
Sourcepub fn should_refresh(&self, threshold: Duration) -> bool
pub fn should_refresh(&self, threshold: Duration) -> bool
Checks if the token should be refreshed.
Returns true if the token will expire within the given threshold.
Sourcepub fn time_until_expiry(&self) -> Option<Duration>
pub fn time_until_expiry(&self) -> Option<Duration>
Returns the time until expiration, if known.
Trait Implementations§
Source§impl Clone for OAuth2Token
impl Clone for OAuth2Token
Source§fn clone(&self) -> OAuth2Token
fn clone(&self) -> OAuth2Token
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OAuth2Token
impl Debug for OAuth2Token
Source§impl Drop for OAuth2Token
impl Drop for OAuth2Token
Auto Trait Implementations§
impl Freeze for OAuth2Token
impl RefUnwindSafe for OAuth2Token
impl Send for OAuth2Token
impl Sync for OAuth2Token
impl Unpin for OAuth2Token
impl UnwindSafe for OAuth2Token
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
Mutably borrows from an owned value. Read more