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 finish_response( &self, req: &AuthRequest, response: &mut AuthResponse, ) -> AuthResult<()>

Finalize session cookies and Bearer response headers.

Source§

impl<S: AuthSchema> SessionManager<S>

Source

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

Source

pub fn with_adapter_user_fields(self, fields: UserConfig) -> Self

Select adapter transforms separately from public field visibility.

Source

pub fn with_user_metadata(self, metadata: MetadataMap) -> Self

Attach enabled user plugin schemas for database and cache projections.

Source

pub async fn session_view( &self, session: &impl AuthSession, ) -> AuthResult<SessionView>

Source

pub async fn internal_session_view( &self, session: &impl AuthSession, ) -> AuthResult<SessionView>

Include hidden session fields for trusted callbacks before public output filtering.

Source

pub async fn internal_data( &self, user: &impl AuthUser, session: &impl AuthSession, ) -> AuthResult<SessionData>

Project an adapter result without removing fields available to trusted callbacks.

Write session credentials and retain the supplied identity for endpoint after hooks.

Write credentials while preserving the native User value for endpoint after hooks.

Issue credentials while keeping signing-key reads and writes in the active transaction.

Install a plugin-provided signer without coupling core to the plugin implementation.

Source

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

Create a new session for a user

Source

pub async fn create_session_for_id( &self, user_id: SchemaValue<String>, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<SessionView>

Preserve the selected runtime User ID, including an omitted ID, during session creation.

Source

pub async fn create_session_with_lifetime( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, expires_in: Duration, ) -> AuthResult<SessionView>

Create a session with a lifetime that overrides the configured default.

Source

pub async fn create_session_for_id_with_lifetime( &self, user_id: SchemaValue<String>, ip_address: Option<String>, user_agent: Option<String>, expires_in: Duration, ) -> AuthResult<SessionView>

Create a session from a native User ID with an explicit lifetime.

Source

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

Read a session directly from the server store and refresh its expiry.

Source

pub async fn resolve( &self, req: &AuthRequest, read: SessionRead, ) -> AuthResult<SessionResolution>

Resolve an HTTP session and queue any cookie updates on the request.

Source

pub async fn resolve_native( &self, req: &AuthRequest, read: SessionRead, ) -> AuthResult<SessionResolution<NativeSessionData>>

Resolve a session while preserving the User value selected by the adapter.

Source

pub async fn write_cache( &self, req: &AuthRequest, data: &SessionData, dont_remember: bool, ) -> AuthResult<()>

Write the configured cache from authenticated session data.

Source

pub fn dont_remember(&self, req: &AuthRequest) -> bool

Read the signed marker for a browser-session-only login.

Source

pub fn clear_cookies(&self, req: &AuthRequest) -> AuthResult<()>

Expire session credentials and every cache chunk received on the request.

Source

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

Delete a session

Source

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

Delete all sessions for a user

Source

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

Get all active sessions for a user

Source

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

Project active sessions while preserving cached undefined application fields.

Source

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

Revoke a specific session by token

Source

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

Revoke all sessions for a user

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

Source

pub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>

Cleanup expired sessions

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).

Returns true when fresh_age is set and session.created_at() + fresh_age > now. If fresh_age is None, the session is never considered fresh.

Source

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

Validate session token format

Source

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

Extract and verify a session cookie or an explicitly enabled Bearer token.

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

Auto Trait Implementations§

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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