Skip to main content

TokenProvider

Trait TokenProvider 

Source
pub trait TokenProvider:
    Send
    + Sync
    + 'static {
    // Required method
    fn get_token<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<String, OAuthClientError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for dynamic token providers.

Implement this to provide bearer tokens that are acquired and refreshed at runtime (e.g., via OAuth 2.0 grants).

§Example

use async_trait::async_trait;
use tower_mcp::client::{TokenProvider, OAuthClientError};

struct StaticTokenProvider(String);

#[async_trait]
impl TokenProvider for StaticTokenProvider {
    async fn get_token(&self) -> Result<String, OAuthClientError> {
        Ok(self.0.clone())
    }
}

Required Methods§

Source

fn get_token<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<String, OAuthClientError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a valid bearer token.

Implementations should cache tokens and return cached values when still valid. This method may be called concurrently from multiple tasks.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§