Skip to main content

AuthenticationStrategy

Trait AuthenticationStrategy 

Source
pub trait AuthenticationStrategy<I>: Send + Sync {
    // Required method
    fn authenticate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        parts: &'life1 Parts,
    ) -> Pin<Box<dyn Future<Output = Result<Option<I>, AuthError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for an authentication strategy.

A strategy is responsible for extracting credentials from a request and validating them to produce an identity.

Required Methods§

Source

fn authenticate<'life0, 'life1, 'async_trait>( &'life0 self, parts: &'life1 Parts, ) -> Pin<Box<dyn Future<Output = Result<Option<I>, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Attempt to authenticate the request.

Returns:

  • Ok(Some(identity)) if authentication was successful.
  • Ok(None) if the strategy did not find relevant credentials (e.g., missing header).
  • Err(AuthError) if authentication failed (e.g., invalid token, DB error).

Implementors§

Source§

impl<F, I, Fut> AuthenticationStrategy<I> for HeaderStrategy<F, I>
where F: Fn(String) -> Fut + Send + Sync, Fut: Future<Output = Result<Option<I>, AuthError>> + Send, I: Send + Sync + 'static,

Source§

impl<P, I> AuthenticationStrategy<I> for BasicStrategy<P, I>
where P: BasicAuthenticator<Identity = I> + Send + Sync, I: Send + Sync + 'static,

Source§

impl<P, I> AuthenticationStrategy<I> for SessionStrategy<P, I>
where P: SessionProvider<Identity = I> + Send + Sync, I: Send + Sync + 'static,

Source§

impl<V, I> AuthenticationStrategy<I> for TokenStrategy<V, I>
where V: TokenValidator<Identity = I> + Send + Sync, I: Send + Sync + 'static,