TokenHandler

Trait TokenHandler 

Source
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(
        &self,
        token: String,
        refresh_token: Option<String>,
        expires_in: u64,
    );
}
Expand description

Trait for handling token usage and renewal.

Required Methods§

Source

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.

Source

fn set_tokens( &self, token: String, refresh_token: Option<String>, expires_in: u64, )

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.

Implementors§