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§
Sourcefn 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 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,
Sourcefn 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 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,
Sourcefn 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 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
Sourcefn 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 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.
Trait Implementations§
Source§impl SessionProvider for Box<dyn SessionProvider>
Implementation of SessionProvider for Box
This allows for dynamic dispatch of session providers
impl SessionProvider for Box<dyn SessionProvider>
Implementation of SessionProvider for Box
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,
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,
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,
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,
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,
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
impl SessionProvider for Box<dyn SessionProvider>
Implementation of SessionProvider for Box