pub struct SessionProvider<S, U>{ /* private fields */ }Expand description
Session-based authentication provider
Implementations§
Source§impl<S, U> SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData>,
U: Authenticatable + Clone,
impl<S, U> SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData>,
U: Authenticatable + Clone,
Sourcepub fn new(
storage: S,
session_duration: Duration,
cleanup_interval: Duration,
) -> Self
pub fn new( storage: S, session_duration: Duration, cleanup_interval: Duration, ) -> Self
Create new session provider
pub fn cleanup_interval(&self) -> Duration
Sourcepub fn with_default_config(storage: S) -> Self
pub fn with_default_config(storage: S) -> Self
Create session provider with default settings
Sourcepub async fn create_session(
&self,
user: &U,
csrf_token: Option<String>,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<SessionId>
pub async fn create_session( &self, user: &U, csrf_token: Option<String>, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<SessionId>
Create a new session for authenticated user
Sourcepub async fn validate_session(
&self,
session_id: &SessionId,
) -> AuthResult<SessionData>
pub async fn validate_session( &self, session_id: &SessionId, ) -> AuthResult<SessionData>
Validate session and return session data
Sourcepub async fn extend_session(&self, session_id: &SessionId) -> AuthResult<()>
pub async fn extend_session(&self, session_id: &SessionId) -> AuthResult<()>
Extend session expiration
Sourcepub async fn destroy_session(&self, session_id: &SessionId) -> AuthResult<()>
pub async fn destroy_session(&self, session_id: &SessionId) -> AuthResult<()>
Delete session (logout)
Sourcepub async fn cleanup_expired(&self) -> AuthResult<u64>
pub async fn cleanup_expired(&self) -> AuthResult<u64>
Clean up expired sessions
Trait Implementations§
Source§impl<S, U> AuthProvider<U> for SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData>,
U: Authenticatable + Clone,
impl<S, U> AuthProvider<U> for SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData>,
U: Authenticatable + Clone,
type Token = SessionId
type Credentials = SessionCredentials
Source§fn authenticate<'life0, 'life1, 'async_trait>(
&'life0 self,
credentials: &'life1 Self::Credentials,
) -> Pin<Box<dyn Future<Output = AuthResult<AuthenticationResult<U, Self::Token>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn authenticate<'life0, 'life1, 'async_trait>(
&'life0 self,
credentials: &'life1 Self::Credentials,
) -> Pin<Box<dyn Future<Output = AuthResult<AuthenticationResult<U, Self::Token>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Authenticate user with credentials and return a token
Source§fn validate_token<'life0, 'life1, 'async_trait>(
&'life0 self,
_token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<U>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn validate_token<'life0, 'life1, 'async_trait>(
&'life0 self,
_token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<U>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Validate an existing token and return user information
Source§fn revoke_token<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn revoke_token<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Revoke a token
Source§fn provider_name(&self) -> &str
fn provider_name(&self) -> &str
Get provider name for identification
Source§fn refresh_token<'life0, 'life1, 'async_trait>(
&'life0 self,
_token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<Self::Token>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn refresh_token<'life0, 'life1, 'async_trait>(
&'life0 self,
_token: &'life1 Self::Token,
) -> Pin<Box<dyn Future<Output = AuthResult<Self::Token>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Refresh a token if supported
Source§impl<S, U> Debug for SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData> + Debug,
U: Authenticatable + Debug,
impl<S, U> Debug for SessionProvider<S, U>where
S: SessionStorage<SessionId = SessionId, SessionData = SessionData> + Debug,
U: Authenticatable + Debug,
Auto Trait Implementations§
impl<S, U> Freeze for SessionProvider<S, U>
impl<S, U> RefUnwindSafe for SessionProvider<S, U>where
U: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, U> Send for SessionProvider<S, U>
impl<S, U> Sync for SessionProvider<S, U>
impl<S, U> Unpin for SessionProvider<S, U>where
U: Unpin,
impl<S, U> UnwindSafe for SessionProvider<S, U>where
S: RefUnwindSafe,
U: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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