Skip to main content

AuthPlugin

Trait AuthPlugin 

Source
pub trait AuthPlugin<DB: DatabaseAdapter>: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn routes(&self) -> Vec<AuthRoute>;
    fn on_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        req: &'life1 AuthRequest,
        ctx: &'life2 AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<Option<AuthResponse>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn on_init<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 mut AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_user_created<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        user: &'life1 DB::User,
        ctx: &'life2 AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_session_created<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session: &'life1 DB::Session,
        ctx: &'life2 AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_user_deleted<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        user_id: &'life1 str,
        ctx: &'life2 AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_session_deleted<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_token: &'life1 str,
        ctx: &'life2 AuthContext<DB>,
    ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Plugin trait that all authentication plugins must implement.

Generic over DB so that lifecycle hooks receive the adapter’s concrete entity types (e.g., DB::User, DB::Session).

Required Methods§

Source

fn name(&self) -> &'static str

Plugin name - should be unique

Source

fn routes(&self) -> Vec<AuthRoute>

Routes that this plugin handles

Source

fn on_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, req: &'life1 AuthRequest, ctx: &'life2 AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<Option<AuthResponse>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called for each request - return Some(response) to handle, None to pass through

Provided Methods§

Source

fn on_init<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 mut AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when the plugin is initialized

Source

fn on_user_created<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user: &'life1 DB::User, ctx: &'life2 AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a user is created

Source

fn on_session_created<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session: &'life1 DB::Session, ctx: &'life2 AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a session is created

Source

fn on_user_deleted<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user_id: &'life1 str, ctx: &'life2 AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before a user is deleted

Source

fn on_session_deleted<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_token: &'life1 str, ctx: &'life2 AuthContext<DB>, ) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before a session is deleted

Implementors§