Skip to main content

AuthProvider

Trait AuthProvider 

Source
pub trait AuthProvider: Send + Sync {
    // Required method
    fn validate_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        authorization_header: Option<&'life1 str>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<AuthContext>, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn auth_scheme(&self) -> &'static str { ... }
    fn is_required(&self) -> bool { ... }
}
Expand description

Core authentication provider trait. This is the main abstraction that MCP servers use for authentication.

Required Methods§

Source

fn validate_request<'life0, 'life1, 'async_trait>( &'life0 self, authorization_header: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<Option<AuthContext>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Validate an incoming request and extract authentication context.

This method receives the authorization header value and should:

  1. Parse the authentication token (e.g., Bearer token)
  2. Validate the token
  3. Return the authentication context if valid

The authorization_header parameter contains the value of the Authorization header, if present (e.g., “Bearer eyJhbGci…”)

Provided Methods§

Source

fn auth_scheme(&self) -> &'static str

Get the authentication scheme this provider uses (e.g., “Bearer”, “Basic”).

Source

fn is_required(&self) -> bool

Check if this provider requires authentication for all requests.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§