pub struct TokenManager { /* private fields */ }Expand description
Manages Questrade OAuth tokens with auto-refresh.
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub async fn new(
refresh_token: String,
practice: bool,
on_token_refresh: Option<OnTokenRefresh>,
cached_token: Option<CachedToken>,
) -> Result<Self>
pub async fn new( refresh_token: String, practice: bool, on_token_refresh: Option<OnTokenRefresh>, cached_token: Option<CachedToken>, ) -> Result<Self>
Create a new TokenManager with the given refresh token.
on_token_refresh is called whenever the token is refreshed; pass None
for a no-op (e.g. in tests that don’t need persistence).
If cached_token is provided and still valid, the initial token refresh
is skipped and the cached credentials are used directly.
Sourcepub async fn new_with_login_url(
refresh_token: String,
on_token_refresh: Option<OnTokenRefresh>,
login_url: String,
cached_token: Option<CachedToken>,
) -> Result<Self>
pub async fn new_with_login_url( refresh_token: String, on_token_refresh: Option<OnTokenRefresh>, login_url: String, cached_token: Option<CachedToken>, ) -> Result<Self>
Like [new] but accepts an explicit login URL.
Used internally and in tests (e.g. to point at a wiremock server).
Sourcepub async fn get_token(&self) -> Result<(String, String)>
pub async fn get_token(&self) -> Result<(String, String)>
Get a valid access token and API server URL, refreshing if needed.
Sourcepub async fn force_refresh(&self) -> Result<(String, String)>
pub async fn force_refresh(&self) -> Result<(String, String)>
Force a token refresh even if the current token has not expired.
Used when the server returns 401 Unauthorized, indicating the access token was revoked server-side before its stated expiry.
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 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