pub struct SessionManager { /* private fields */ }Expand description
Owns the SessionStore and mints / resolves / revokes sessions.
Cheap to clone — the underlying store is reference-counted.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(store: Arc<dyn SessionStore>, default_duration: Duration) -> Self
pub fn new(store: Arc<dyn SessionStore>, default_duration: Duration) -> Self
Construct a manager with an explicit default session duration.
Callers wanting the standard 30-day lifetime should use
SessionManager::with_default_duration.
Sourcepub fn with_default_duration(store: Arc<dyn SessionStore>) -> Self
pub fn with_default_duration(store: Arc<dyn SessionStore>) -> Self
Construct with the DEFAULT_SESSION_DURATION (30 days).
Sourcepub async fn create(&self, user_id: &str) -> Result<Session>
pub async fn create(&self, user_id: &str) -> Result<Session>
Mint a fresh session for user_id and persist it via the store.
The returned Session carries both the opaque cookie value
(id) and the parallel CSRF token. Call sites set both cookies
on the response (see cookie_for / csrf_cookie_for).
Sourcepub async fn resolve(&self, id: &str) -> Result<Option<Session>>
pub async fn resolve(&self, id: &str) -> Result<Option<Session>>
Resolve a presented session id. Returns Ok(None) for a
missing-or-expired session so callers can treat
“not authenticated” uniformly. Expired rows are left in the table
— the periodic SessionStore::purge_expired sweep removes them.
Sourcepub async fn rotate(&self, old_id: &str) -> Result<Option<Session>>
pub async fn rotate(&self, old_id: &str) -> Result<Option<Session>>
Rotate a session id while preserving the user binding and the
original expires_at. Used on privilege escalation
(e.g. completing a step-up authentication) to defeat session
fixation. Returns Ok(None) if the old id is unknown — caller
can decide whether to surface as 401.
Sourcepub async fn revoke(&self, id: &str) -> Result<bool>
pub async fn revoke(&self, id: &str) -> Result<bool>
Revoke a single session — typically called from /logout.
Sourcepub async fn revoke_for_user(&self, user_id: &str) -> Result<u64>
pub async fn revoke_for_user(&self, user_id: &str) -> Result<u64>
Revoke every session for a user — typically called from “log out of all devices” or after a password change.
Sourcepub fn store(&self) -> &Arc<dyn SessionStore>
pub fn store(&self) -> &Arc<dyn SessionStore>
Borrow the underlying store. Phase 5/6 may want direct access (e.g. for the periodic purge sweep) without going through the manager’s API surface.
Trait Implementations§
Source§impl Clone for SessionManager
impl Clone for SessionManager
Source§fn clone(&self) -> SessionManager
fn clone(&self) -> SessionManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
impl !UnwindSafe for SessionManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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