pub struct CustomHeaderProvider { /* private fields */ }Expand description
Validates a custom HTTP header credential (e.g. X-Internal-Token).
The transport layer extracts the value of the configured header and wraps it
in Credentials::CustomHeader before passing it to this provider.
§Examples
use mcp_kit::auth::{CustomHeaderProvider, AuthenticatedIdentity};
let provider = CustomHeaderProvider::new("x-internal-token", |value| async move {
if value == "trusted" {
Ok(AuthenticatedIdentity::new("internal-service"))
} else {
Err(mcp_kit::McpError::Unauthorized("invalid token".into()))
}
});Implementations§
Source§impl CustomHeaderProvider
impl CustomHeaderProvider
Sourcepub fn new<F, Fut>(header_name: impl Into<String>, f: F) -> Self
pub fn new<F, Fut>(header_name: impl Into<String>, f: F) -> Self
Create a provider that validates values from the named header.
header_name is case-insensitive; it will be normalised to lowercase.
Sourcepub fn header_name(&self) -> &str
pub fn header_name(&self) -> &str
The header name this provider expects (normalised to lowercase).
Trait Implementations§
Source§impl AuthProvider for CustomHeaderProvider
impl AuthProvider for CustomHeaderProvider
Source§fn authenticate<'a>(&'a self, credentials: &'a Credentials) -> AuthFuture<'a>
fn authenticate<'a>(&'a self, credentials: &'a Credentials) -> AuthFuture<'a>
Validate
credentials and return the authenticated identity, or an error.Source§fn accepts(&self, credentials: &Credentials) -> bool
fn accepts(&self, credentials: &Credentials) -> bool
Returns
true if this provider knows how to handle the given credential
variant. Used by CompositeAuthProvider to select the right delegate
without unnecessarily calling authenticate.Auto Trait Implementations§
impl Freeze for CustomHeaderProvider
impl !RefUnwindSafe for CustomHeaderProvider
impl Send for CustomHeaderProvider
impl Sync for CustomHeaderProvider
impl Unpin for CustomHeaderProvider
impl UnsafeUnpin for CustomHeaderProvider
impl !UnwindSafe for CustomHeaderProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more