pub struct TokenManager { /* private fields */ }
Expand description
Manages OAuth tokens including refresh functionality
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub fn new(
token: TokenResponse,
provider: Provider,
config: DeviceFlowConfig,
) -> Result<Self>
pub fn new( token: TokenResponse, provider: Provider, config: DeviceFlowConfig, ) -> Result<Self>
Create a new token manager
Sourcepub fn from_token(token: TokenResponse) -> Self
pub fn from_token(token: TokenResponse) -> Self
Create a token manager from an existing token (for deserialization)
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the current access token
Sourcepub fn token(&self) -> &TokenResponse
pub fn token(&self) -> &TokenResponse
Get the current token response
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is expired
Sourcepub fn expires_within(&self, duration: Duration) -> bool
pub fn expires_within(&self, duration: Duration) -> bool
Check if the token will expire within the given duration
Sourcepub fn remaining_lifetime(&self) -> Option<Duration>
pub fn remaining_lifetime(&self) -> Option<Duration>
Get the remaining lifetime of the token
Sourcepub async fn refresh(&mut self) -> Result<()>
pub async fn refresh(&mut self) -> Result<()>
Refresh the token if a refresh token is available
Sourcepub async fn refresh_token(&self, refresh_token: &str) -> Result<TokenResponse>
pub async fn refresh_token(&self, refresh_token: &str) -> Result<TokenResponse>
Refresh the token and return the new token without updating the manager
Sourcepub async fn get_valid_token(&mut self) -> Result<&str>
pub async fn get_valid_token(&mut self) -> Result<&str>
Get a valid access token, refreshing if necessary
Create an authorization header value
Sourcepub fn with_provider(self, provider: Provider) -> Self
pub fn with_provider(self, provider: Provider) -> Self
Update the provider (useful when deserializing)
Sourcepub fn with_config(self, config: DeviceFlowConfig) -> Result<Self>
pub fn with_config(self, config: DeviceFlowConfig) -> Result<Self>
Update the configuration (useful when deserializing)
Trait Implementations§
Source§impl Clone for TokenManager
impl Clone for TokenManager
Source§fn clone(&self) -> TokenManager
fn clone(&self) -> TokenManager
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 moreAuto Trait Implementations§
impl Freeze for TokenManager
impl !RefUnwindSafe for TokenManager
impl Send for TokenManager
impl Sync for TokenManager
impl Unpin for TokenManager
impl !UnwindSafe for TokenManager
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