SessionProvider

Trait SessionProvider 

Source
pub trait SessionProvider: Send + Sync {
    // Required methods
    fn create_session<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user_id: &'life1 UserId,
        user_agent: Option<String>,
        ip_address: Option<String>,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_session<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token: &'life1 SessionToken,
    ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_session<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token: &'life1 SessionToken,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn cleanup_expired_sessions<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete_sessions_for_user<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user_id: &'life1 UserId,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for session token providers

This trait abstracts the creation and validation of session tokens, allowing for different implementations such as JWT tokens or database-backed opaque tokens.

Required Methods§

Source

fn create_session<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, user_agent: Option<String>, ip_address: Option<String>, duration: Duration, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new session token for the given user

§Arguments
  • user_id - The ID of the user to create a session for
  • user_agent - Optional user agent string
  • ip_address - Optional IP address
  • duration - How long the session should be valid for
§Returns

A new Session with an appropriate token

Source

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate and retrieve session information from a token

§Arguments
  • token - The session token to validate
§Returns

The Session if the token is valid, or an error if invalid/expired

Source

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate a session token

For stateless providers (like JWT), this may be a no-op. For stateful providers, this should remove the session from storage.

§Arguments
  • token - The session token to invalidate
Source

fn cleanup_expired_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clean up expired sessions

For stateless providers (like JWT), this is typically a no-op. For stateful providers, this should remove expired sessions from storage.

Source

fn delete_sessions_for_user<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate all sessions for a specific user

§Arguments
  • user_id - The ID of the user whose sessions should be invalidated
§Note

For stateless providers like JWT, this may not be fully supported without implementing a token blacklist or revocation mechanism.

Trait Implementations§

Source§

impl SessionProvider for Box<dyn SessionProvider>

Implementation of SessionProvider for Box This allows for dynamic dispatch of session providers

Source§

fn create_session<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, user_agent: Option<String>, ip_address: Option<String>, duration: Duration, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new session token for the given user Read more
Source§

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate and retrieve session information from a token Read more
Source§

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate a session token Read more
Source§

fn cleanup_expired_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clean up expired sessions Read more
Source§

fn delete_sessions_for_user<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate all sessions for a specific user Read more

Implementations on Foreign Types§

Source§

impl SessionProvider for Box<dyn SessionProvider>

Implementation of SessionProvider for Box This allows for dynamic dispatch of session providers

Source§

fn create_session<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, user_agent: Option<String>, ip_address: Option<String>, duration: Duration, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<Session, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 SessionToken, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn cleanup_expired_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn delete_sessions_for_user<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 UserId, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§