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§
Sourcefn 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,
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:
- Parse the authentication token (e.g., Bearer token)
- Validate the token
- 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§
Sourcefn auth_scheme(&self) -> &'static str
fn auth_scheme(&self) -> &'static str
Get the authentication scheme this provider uses (e.g., “Bearer”, “Basic”).
Sourcefn is_required(&self) -> bool
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".