Skip to main content

TokenHandler

Trait TokenHandler 

Source
pub trait TokenHandler:
    'static
    + Send
    + Sync {
    // Required methods
    fn initialize_middleware(
        &self,
        state_registry: &StateRegistry,
        identity_config: Configuration,
        key_store: KeyStore<KeySlotIds>,
    ) -> 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;

    // Provided method
    fn set_sm_login_method<'life0, 'async_trait>(
        &'life0 self,
        _login_method: ServiceAccountLoginMethod,
    ) -> 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§

Source

fn initialize_middleware( &self, state_registry: &StateRegistry, identity_config: Configuration, key_store: KeyStore<KeySlotIds>, ) -> 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<'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.

Provided Methods§

Source

fn set_sm_login_method<'life0, 'async_trait>( &'life0 self, _login_method: ServiceAccountLoginMethod, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Secrets-Manager-only hook for storing the Service Account login method on the handler itself. SM tokens are not persisted, so the login method lives in-memory on the SecretsManagerTokenHandler implementation. The default no-op implementation is intentional: handlers that do not back Secrets Manager (PM, Noop, ClientManaged) should ignore this call. This will be removed once the auth crate fully owns the login process.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§