Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager<S: AuthSchema> { /* private fields */ }
Expand description

Session manager handles session creation, validation, and cleanup

Implementations§

Source§

impl<S: AuthSchema> SessionManager<S>

Source

pub fn new(config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>) -> Self

Source

pub async fn create_session( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<S::Session>

Create a new session for a user

§Errors

Propagates errors from session hooks or persistence.

Source

pub async fn create_session_record( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<AdapterRecord<S::Session>>

Create a real session and retain its declared adapter output.

§Errors

Propagates errors from persistence or configured callbacks.

Source

pub async fn create_session_record_in_transaction( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, database: &dyn AuthTransaction<S>, ) -> AuthResult<AdapterRecord<S::Session>>

Create the session through an existing authentication transaction.

§Errors

Propagates transaction creation and callback errors.

Source

pub async fn get_session(&self, token: &str) -> AuthResult<Option<S::Session>>

Read and refresh a session according to the configured expiry window.

§Errors

Propagates errors from the session store.

Source

pub async fn read_session( &self, token: &str, options: SessionReadOptions, ) -> AuthResult<SessionRead<S::Session>>

Read persisted session state with explicit control over side effects. Deferred browser reads leave expired rows in place until a later write.

§Errors

Propagates errors from the session store.

Source

pub async fn read_loaded_session( &self, session: S::Session, options: SessionReadOptions, ) -> AuthResult<SessionRead<S::Session>>

Apply the session lifecycle to a snapshot already read from this store. Session handlers use this to retain their original hook context without looking up the session a second time. Validation and refresh still run. The supplied snapshot must come from this manager’s store, never client input.

§Errors

Propagates errors from the session store.

Source

pub async fn read_loaded_session_record( &self, session: AdapterRecord<S::Session>, options: SessionReadOptions, ) -> AuthResult<SessionRead<AdapterRecord<S::Session>>>

Apply the same physical expiry/refresh lifecycle to retained adapter output. The record must originate from this manager’s actual initialized store.

Source

pub fn request_disables_refresh(&self, request: &impl SessionRequest) -> bool

Whether signed browser preferences or the query suppress refresh. Query values use the upstream Boolean coercion: any nonempty string, including false, disables refreshing.

The independently signed browser session preference.

Source

pub async fn delete_session(&self, token: &str) -> AuthResult<()>

Delete a session

§Errors

Propagates errors from the session store.

Source

pub async fn delete_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<()>

Delete all sessions for a user

§Errors

Propagates errors from the session store.

Source

pub async fn list_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<Vec<S::Session>>

Get all active sessions for a user

§Errors

Propagates errors from the session store.

Source

pub async fn revoke_session(&self, token: &str) -> AuthResult<bool>

Revoke a specific session by token

§Errors

Propagates errors from the session store.

Source

pub async fn revoke_all_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<usize>

Revoke all sessions for a user

§Errors

Propagates errors from the session store.

Source

pub async fn revoke_other_user_sessions( &self, user_id: impl AsRef<str>, current_token: &str, ) -> AuthResult<usize>

Revoke all sessions for a user except the current one

§Errors

Propagates errors from the session store.

Source

pub fn is_session_fresh(&self, session: &impl AuthSession) -> bool

Check whether a session is “fresh” (created recently enough for sensitive operations like password change or account deletion).

A positive freshness window requires creation time within that window. None and zero disable the restriction, matching upstream freshAge: 0.

Source

pub fn validate_token_format(&self, token: &str) -> bool

Validate session token format

Source

pub fn extract_session_token(&self, req: &impl SessionRequest) -> Option<String>

Extract a verified session token from the configured cookie.

The core runtime does not authenticate bearer headers. The separate bearer plugin may establish a signed cookie before this parser runs.

Trait Implementations§

Source§

impl<S: AuthSchema> Clone for SessionManager<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: AuthSchema> Debug for SessionManager<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for SessionManager<S>

§

impl<S> !UnwindSafe for SessionManager<S>

§

impl<S> Freeze for SessionManager<S>
where Arc<dyn AuthStore<S>>: Freeze,

§

impl<S> Send for SessionManager<S>
where Arc<dyn AuthStore<S>>: Send,

§

impl<S> Sync for SessionManager<S>
where Arc<dyn AuthStore<S>>: Sync,

§

impl<S> Unpin for SessionManager<S>
where Arc<dyn AuthStore<S>>: Unpin,

§

impl<S> UnsafeUnpin for SessionManager<S>
where Arc<dyn AuthStore<S>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more