pub struct TokenManager { /* private fields */ }Expand description
Manages token persistence, loading, and automatic refresh.
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub fn new(tokens: Tokens, client_id: String, token_path: PathBuf) -> Self
pub fn new(tokens: Tokens, client_id: String, token_path: PathBuf) -> Self
Create a new token manager with the given tokens and client configuration.
Sourcepub async fn get_access_token(&self) -> Result<String, XApiError>
pub async fn get_access_token(&self) -> Result<String, XApiError>
Get the current access token, refreshing if needed.
Sourcepub fn tokens_lock(&self) -> Arc<RwLock<Tokens>>
pub fn tokens_lock(&self) -> Arc<RwLock<Tokens>>
Get a shared reference to the tokens lock for direct access.
Sourcepub async fn refresh_if_needed(&self) -> Result<(), XApiError>
pub async fn refresh_if_needed(&self) -> Result<(), XApiError>
Refresh the access token if it is within 5 minutes of expiring.
Acquires refresh_lock to prevent concurrent refresh attempts.
X API refresh tokens are single-use, so a second concurrent refresh
with the old token would fail and revoke the session.
Auto Trait Implementations§
impl !Freeze for TokenManager
impl !RefUnwindSafe for TokenManager
impl Send for TokenManager
impl Sync for TokenManager
impl Unpin for TokenManager
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more