pub struct SessionManager<S: AuthSchema> { /* private fields */ }Expand description
Session manager handles session creation, validation, and cleanup
Implementations§
Source§impl<S: AuthSchema> SessionManager<S>
impl<S: AuthSchema> SessionManager<S>
pub fn new(config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>) -> Self
Sourcepub async fn create_session(
&self,
user: &impl AuthUser,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<S::Session>
pub async fn create_session( &self, user: &impl AuthUser, ip_address: Option<String>, user_agent: Option<String>, ) -> AuthResult<S::Session>
Sourcepub async fn create_session_record(
&self,
user: &impl AuthUser,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<AdapterRecord<S::Session>>
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.
Sourcepub 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>>
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.
Sourcepub async fn get_session(&self, token: &str) -> AuthResult<Option<S::Session>>
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.
Sourcepub async fn read_session(
&self,
token: &str,
options: SessionReadOptions,
) -> AuthResult<SessionRead<S::Session>>
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.
Sourcepub async fn read_loaded_session(
&self,
session: S::Session,
options: SessionReadOptions,
) -> AuthResult<SessionRead<S::Session>>
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.
Sourcepub async fn read_loaded_session_record(
&self,
session: AdapterRecord<S::Session>,
options: SessionReadOptions,
) -> AuthResult<SessionRead<AdapterRecord<S::Session>>>
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.
Sourcepub fn request_disables_refresh(&self, request: &impl SessionRequest) -> bool
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.
Sourcepub async fn delete_session(&self, token: &str) -> AuthResult<()>
pub async fn delete_session(&self, token: &str) -> AuthResult<()>
Sourcepub async fn delete_user_sessions(
&self,
user_id: impl AsRef<str>,
) -> AuthResult<()>
pub async fn delete_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<()>
Sourcepub async fn list_user_sessions(
&self,
user_id: impl AsRef<str>,
) -> AuthResult<Vec<S::Session>>
pub async fn list_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<Vec<S::Session>>
Sourcepub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
pub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
Sourcepub async fn revoke_all_user_sessions(
&self,
user_id: impl AsRef<str>,
) -> AuthResult<usize>
pub async fn revoke_all_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<usize>
Sourcepub async fn revoke_other_user_sessions(
&self,
user_id: impl AsRef<str>,
current_token: &str,
) -> AuthResult<usize>
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.
Sourcepub fn is_session_fresh(&self, session: &impl AuthSession) -> bool
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.
Sourcepub fn validate_token_format(&self, token: &str) -> bool
pub fn validate_token_format(&self, token: &str) -> bool
Validate session token format
Sourcepub fn extract_session_token(&self, req: &impl SessionRequest) -> Option<String>
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.