pub struct TokenManager { /* private fields */ }Expand description
Token manager for handling authentication.
This struct manages the access token lifecycle:
- Acquires new tokens when needed
- Caches tokens to avoid unnecessary requests
- Automatically refreshes tokens before expiry
Thread-safe: Uses RwLock for concurrent access.
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub fn new(
api_key: impl Into<String>,
secret: impl Into<String>,
base_url: impl Into<String>,
http_client: HttpClient,
) -> Self
pub fn new( api_key: impl Into<String>, secret: impl Into<String>, base_url: impl Into<String>, http_client: HttpClient, ) -> Self
Create a new token manager.
Sourcepub async fn token(&self) -> Result<String>
pub async fn token(&self) -> Result<String>
Get a valid access token.
Returns a cached token if still valid, otherwise acquires a new one.
Sourcepub async fn is_expired(&self) -> bool
pub async fn is_expired(&self) -> bool
Check if the cached token is expired.
Sourcepub async fn clear_token(&self)
pub async fn clear_token(&self)
Clear the cached token.
Sourcepub async fn get_cached_token(&self) -> String
pub async fn get_cached_token(&self) -> String
Get the cached token without triggering refresh.
Trait Implementations§
Auto 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