Skip to main content

TokenProvider

Trait TokenProvider 

Source
pub trait TokenProvider:
    Send
    + Sync
    + 'static {
    // Required method
    fn access_token(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<String, ClientError>> + Send + '_>>;

    // Provided method
    fn invalidate(&self, _token: &str) { ... }
}
Expand description

A source of bearer access tokens.

Implementations are responsible for their own caching and refresh; BearerAuthInterceptor calls access_token before every request.

Required Methods§

Source

fn access_token( &self, ) -> Pin<Box<dyn Future<Output = Result<String, ClientError>> + Send + '_>>

Returns a currently-valid access token.

§Errors

Returns a ClientError when a token cannot be produced (e.g. the token endpoint rejected the credentials or is unreachable).

Provided Methods§

Source

fn invalidate(&self, _token: &str)

Tells the provider the agent rejected token (HTTP 401), so it should not hand that token out again.

BearerAuthInterceptor calls this; the next access_token should then produce a different token. Only token is meant: a provider that has already moved on to a newer one keeps it.

Not overriding it (the default does nothing) means a rejected token — revoked, rotated signing key, wrong audience — keeps being sent, and every call fails the same way, until the provider’s own expiry replaces it. OAuth2ClientCredentials overrides it; StaticTokenProvider has nothing else to offer and keeps the default.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§