pub struct ApiKeyProvider { /* private fields */ }Expand description
Validates X-Api-Key: <key> header credentials (or ?api_key= query param,
which the transport layer normalises into the same Credentials::ApiKey variant).
§Examples
Static key list:
use mcp_kit::auth::ApiKeyProvider;
let provider = ApiKeyProvider::new(["key-abc-123", "key-def-456"]);Custom async validator:
use mcp_kit::auth::{ApiKeyProvider, AuthenticatedIdentity};
let provider = ApiKeyProvider::with_validator(|key| async move {
// look up the key in a database, etc.
Ok(AuthenticatedIdentity::new("service-a").with_scopes(["read"]))
});Implementations§
Source§impl ApiKeyProvider
impl ApiKeyProvider
Sourcepub fn new(keys: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn new(keys: impl IntoIterator<Item = impl Into<String>>) -> Self
Accept any API key in the given iterator. The identity subject is set to the key value itself.
Sourcepub fn with_validator<F, Fut>(f: F) -> Self
pub fn with_validator<F, Fut>(f: F) -> Self
Use a custom async validator.
Trait Implementations§
Source§impl AuthProvider for ApiKeyProvider
impl AuthProvider for ApiKeyProvider
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 ApiKeyProvider
impl !RefUnwindSafe for ApiKeyProvider
impl Send for ApiKeyProvider
impl Sync for ApiKeyProvider
impl Unpin for ApiKeyProvider
impl UnsafeUnpin for ApiKeyProvider
impl !UnwindSafe for ApiKeyProvider
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