pub struct ApiKeyAuthenticator<R>where
R: ApiKeyRepository,{ /* private fields */ }Expand description
Authenticator that validates API keys from requests.
This authenticator extracts API keys from configured locations (header, query parameter, or Authorization header) and validates them against a repository.
§Example
ⓘ
use actix_security::http::security::api_key::{
ApiKeyAuthenticator, ApiKeyConfig, ApiKey, InMemoryApiKeyRepository,
};
let repository = InMemoryApiKeyRepository::new()
.with_key(ApiKey::new("sk_live_abc123")
.roles(vec!["API_USER".into()])
.authorities(vec!["api:read".into()]));
let authenticator = ApiKeyAuthenticator::new(repository)
.config(ApiKeyConfig::header("X-API-Key"));Implementations§
Source§impl<R> ApiKeyAuthenticator<R>where
R: ApiKeyRepository,
impl<R> ApiKeyAuthenticator<R>where
R: ApiKeyRepository,
Sourcepub fn new(repository: R) -> ApiKeyAuthenticator<R>
pub fn new(repository: R) -> ApiKeyAuthenticator<R>
Creates a new API key authenticator with the given repository.
Creates a new API key authenticator with a shared repository.
Sourcepub fn config(self, config: ApiKeyConfig) -> ApiKeyAuthenticator<R>
pub fn config(self, config: ApiKeyConfig) -> ApiKeyAuthenticator<R>
Sets the configuration for this authenticator.
Trait Implementations§
Source§impl<R> Authenticator for ApiKeyAuthenticator<R>where
R: ApiKeyRepository + 'static,
impl<R> Authenticator for ApiKeyAuthenticator<R>where
R: ApiKeyRepository + 'static,
Source§impl<R> Clone for ApiKeyAuthenticator<R>where
R: ApiKeyRepository,
impl<R> Clone for ApiKeyAuthenticator<R>where
R: ApiKeyRepository,
Source§fn clone(&self) -> ApiKeyAuthenticator<R>
fn clone(&self) -> ApiKeyAuthenticator<R>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<R> Freeze for ApiKeyAuthenticator<R>
impl<R> RefUnwindSafe for ApiKeyAuthenticator<R>where
R: RefUnwindSafe,
impl<R> Send for ApiKeyAuthenticator<R>
impl<R> Sync for ApiKeyAuthenticator<R>
impl<R> Unpin for ApiKeyAuthenticator<R>
impl<R> UnwindSafe for ApiKeyAuthenticator<R>where
R: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more