pub trait TokenHandler:
'static
+ Send
+ Sync {
// Required methods
fn initialize_middleware(
&self,
login_method: Arc<RwLock<Option<Arc<LoginMethod>>>>,
identity_config: Configuration,
key_store: KeyStore<KeyIds>,
) -> Arc<dyn Middleware>;
fn set_tokens<'life0, 'async_trait>(
&'life0 self,
token: String,
refresh_token: Option<String>,
expires_in: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for handling token usage and renewal.
Required Methods§
Sourcefn initialize_middleware(
&self,
login_method: Arc<RwLock<Option<Arc<LoginMethod>>>>,
identity_config: Configuration,
key_store: KeyStore<KeyIds>,
) -> Arc<dyn Middleware>
fn initialize_middleware( &self, login_method: Arc<RwLock<Option<Arc<LoginMethod>>>>, identity_config: Configuration, key_store: KeyStore<KeyIds>, ) -> Arc<dyn Middleware>
Initialize middleware that handles token attachment and renewal. This middleware should look for the presence of the [bitwarden_api_base::AuthRequired] extension to decide when to attach tokens. It’s then free to attach tokens as it sees fit, including pausing and retrying requests to renew tokens.
Sourcefn set_tokens<'life0, 'async_trait>(
&'life0 self,
token: String,
refresh_token: Option<String>,
expires_in: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_tokens<'life0, 'async_trait>(
&'life0 self,
token: String,
refresh_token: Option<String>,
expires_in: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
This method is available only as a backwards compatibility measure until all the auth-related code is moved out of core. Once that is done, setting tokens should be always done either during renewal (as part of the middleware) or during registration/login, in which case it would be up to the auth crate to internally set those tokens when initializing the client.