pub struct MultiAuthProvider { /* private fields */ }Expand description
Multi-provider authentication that tries providers in order until one succeeds.
This provider allows supporting multiple authentication methods simultaneously
and enables adding custom enterprise authentication providers. Providers are
tried in the order they were added via with_provider().
Provider order matters for authentication precedence - the first successful match wins. Typically, you want faster providers (like API key) before slower ones (like OIDC JWT validation).
§Example
use micromegas_auth::api_key::{ApiKeyAuthProvider, parse_key_ring};
use micromegas_auth::oidc::{OidcAuthProvider, OidcConfig, OidcIssuer};
use micromegas_auth::multi::MultiAuthProvider;
use std::sync::Arc;
// Set up API key provider
let keyring = parse_key_ring(r#"[{"name": "test", "key": "secret"}]"#)?;
let api_key_provider = Arc::new(ApiKeyAuthProvider::new(keyring));
// Set up OIDC provider
let oidc_config = OidcConfig {
issuers: vec![OidcIssuer {
issuer: "https://accounts.google.com".to_string(),
audience: "your-app.apps.googleusercontent.com".to_string(),
}],
jwks_refresh_interval_secs: 3600,
token_cache_size: 1000,
token_cache_ttl_secs: 300,
};
let oidc_provider = Arc::new(OidcAuthProvider::new(oidc_config).await?);
// Create multi-provider with builder pattern
let multi = MultiAuthProvider::new()
.with_provider(api_key_provider)
.with_provider(oidc_provider);
// .with_provider(Arc::new(MyEnterpriseAuthProvider::new())); // Custom provider!Implementations§
Source§impl MultiAuthProvider
impl MultiAuthProvider
Sourcepub fn new() -> MultiAuthProvider
pub fn new() -> MultiAuthProvider
Creates a new empty MultiAuthProvider.
Sourcepub fn with_provider(self, provider: Arc<dyn AuthProvider>) -> MultiAuthProvider
pub fn with_provider(self, provider: Arc<dyn AuthProvider>) -> MultiAuthProvider
Adds a provider to the authentication chain.
Providers are tried in the order they are added. Returns self for chaining.
Trait Implementations§
Source§impl AuthProvider for MultiAuthProvider
impl AuthProvider for MultiAuthProvider
Source§fn validate_request<'life0, 'life1, 'async_trait>(
&'life0 self,
parts: &'life1 dyn RequestParts,
) -> Pin<Box<dyn Future<Output = Result<AuthContext, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MultiAuthProvider: 'async_trait,
fn validate_request<'life0, 'life1, 'async_trait>(
&'life0 self,
parts: &'life1 dyn RequestParts,
) -> Pin<Box<dyn Future<Output = Result<AuthContext, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MultiAuthProvider: 'async_trait,
Validate a request and return authentication context
Auto Trait Implementations§
impl Freeze for MultiAuthProvider
impl !RefUnwindSafe for MultiAuthProvider
impl Send for MultiAuthProvider
impl Sync for MultiAuthProvider
impl Unpin for MultiAuthProvider
impl !UnwindSafe for MultiAuthProvider
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].