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>
Sourcepub fn finish_response(
&self,
req: &AuthRequest,
response: &mut AuthResponse,
) -> AuthResult<()>
pub fn finish_response( &self, req: &AuthRequest, response: &mut AuthResponse, ) -> AuthResult<()>
Finalize session cookies and Bearer response headers.
Source§impl<S: AuthSchema> SessionManager<S>
impl<S: AuthSchema> SessionManager<S>
pub fn new(config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>) -> Self
Sourcepub fn with_adapter_user_fields(self, fields: UserConfig) -> Self
pub fn with_adapter_user_fields(self, fields: UserConfig) -> Self
Select adapter transforms separately from public field visibility.
Sourcepub fn with_user_metadata(self, metadata: MetadataMap) -> Self
pub fn with_user_metadata(self, metadata: MetadataMap) -> Self
Attach enabled user plugin schemas for database and cache projections.
pub async fn session_view( &self, session: &impl AuthSession, ) -> AuthResult<SessionView>
Sourcepub async fn internal_session_view(
&self,
session: &impl AuthSession,
) -> AuthResult<SessionView>
pub async fn internal_session_view( &self, session: &impl AuthSession, ) -> AuthResult<SessionView>
Include hidden session fields for trusted callbacks before public output filtering.
Sourcepub async fn internal_data(
&self,
user: &impl AuthUser,
session: &impl AuthSession,
) -> AuthResult<SessionData>
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.
Sourcepub async fn create_session(
&self,
user: &impl AuthUser,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<SessionView>
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
Sourcepub async fn create_session_for_id(
&self,
user_id: SchemaValue<String>,
ip_address: Option<String>,
user_agent: Option<String>,
) -> AuthResult<SessionView>
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.
Sourcepub async fn create_session_with_lifetime(
&self,
user: &impl AuthUser,
ip_address: Option<String>,
user_agent: Option<String>,
expires_in: Duration,
) -> AuthResult<SessionView>
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.
Sourcepub 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>
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.
Sourcepub async fn get_session(&self, token: &str) -> AuthResult<Option<SessionView>>
pub async fn get_session(&self, token: &str) -> AuthResult<Option<SessionView>>
Read a session directly from the server store and refresh its expiry.
Sourcepub async fn resolve(
&self,
req: &AuthRequest,
read: SessionRead,
) -> AuthResult<SessionResolution>
pub async fn resolve( &self, req: &AuthRequest, read: SessionRead, ) -> AuthResult<SessionResolution>
Resolve an HTTP session and queue any cookie updates on the request.
Sourcepub async fn resolve_native(
&self,
req: &AuthRequest,
read: SessionRead,
) -> AuthResult<SessionResolution<NativeSessionData>>
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.
Sourcepub async fn write_cache(
&self,
req: &AuthRequest,
data: &SessionData,
dont_remember: bool,
) -> AuthResult<()>
pub async fn write_cache( &self, req: &AuthRequest, data: &SessionData, dont_remember: bool, ) -> AuthResult<()>
Write the configured cache from authenticated session data.
Sourcepub fn dont_remember(&self, req: &AuthRequest) -> bool
pub fn dont_remember(&self, req: &AuthRequest) -> bool
Read the signed marker for a browser-session-only login.
Expire session credentials and every cache chunk received on the request.
Sourcepub async fn delete_session(&self, token: &str) -> AuthResult<()>
pub async fn delete_session(&self, token: &str) -> AuthResult<()>
Delete a session
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<()>
Delete all sessions for a user
Sourcepub async fn list_user_sessions(
&self,
user_id: impl AsRef<str>,
) -> AuthResult<Vec<SessionView>>
pub async fn list_user_sessions( &self, user_id: impl AsRef<str>, ) -> AuthResult<Vec<SessionView>>
Get all active sessions for a user
Sourcepub async fn list_user_session_views(
&self,
user_id: impl AsRef<str>,
) -> AuthResult<Vec<SessionView>>
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.
Sourcepub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
pub async fn revoke_session(&self, token: &str) -> AuthResult<bool>
Revoke a specific session by token
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>
Revoke all sessions for a user
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
Sourcepub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>
pub async fn cleanup_expired_sessions(&self) -> AuthResult<usize>
Cleanup expired sessions
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).
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.
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: &AuthRequest) -> Option<String>
pub fn extract_session_token(&self, req: &AuthRequest) -> Option<String>
Extract and verify a session cookie or an explicitly enabled Bearer token.