pub struct AuthContext<S: AuthSchema> {
pub config: Arc<AuthConfig>,
pub database: Arc<dyn AuthStore<S>>,
pub email_provider: Option<Arc<dyn EmailProvider>>,
pub metadata: HashMap<String, Value>,
pub extensions: ContextExtensions,
}Expand description
Context passed to plugin methods.
Fields§
§config: Arc<AuthConfig>§database: Arc<dyn AuthStore<S>>§email_provider: Option<Arc<dyn EmailProvider>>§metadata: HashMap<String, Value>§extensions: ContextExtensionsImplementations§
Source§impl<S: AuthSchema> AuthContext<S>
impl<S: AuthSchema> AuthContext<S>
Sourcepub fn parse_user_fields(
&self,
input: &IndexMap<String, JsValue>,
creation: bool,
) -> Result<FieldValues, FieldInputError>
pub fn parse_user_fields( &self, input: &IndexMap<String, JsValue>, creation: bool, ) -> Result<FieldValues, FieldInputError>
Parse configured user fields at the endpoint boundary before creation validation or adapter hooks. Unknown fields are ignored by this policy.
Sourcepub async fn hash_password(
&self,
hasher: Option<&Arc<dyn PasswordHasher>>,
password: &str,
) -> AuthResult<String>
pub async fn hash_password( &self, hasher: Option<&Arc<dyn PasswordHasher>>, password: &str, ) -> AuthResult<String>
Hash through initialized policies at the current actual endpoint.
§Errors
Propagates policy rejections and original hasher errors.
Sourcepub async fn hash_password_with_context(
&self,
hasher: Option<&Arc<dyn PasswordHasher>>,
password: &str,
context: Option<&PasswordHashContext>,
) -> AuthResult<String>
pub async fn hash_password_with_context( &self, hasher: Option<&Arc<dyn PasswordHasher>>, password: &str, context: Option<&PasswordHashContext>, ) -> AuthResult<String>
Hash for a trusted endpoint call whose logical context is independent of an optional physical request, including server-only APIs.
§Errors
Propagates policy rejections and original hasher errors.
pub fn new(config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>) -> Self
pub fn with_metadata( config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>, metadata: HashMap<String, Value>, ) -> Self
pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn with_extensions(self, extensions: ContextExtensions) -> Self
pub fn email_verification_override( &self, ) -> Option<Arc<VerificationEmailOverrideHandle<S>>>
pub fn user_view(&self, user: &impl AuthUser) -> UserView
Sourcepub fn trusted_user_view(&self, user: &impl AuthUser) -> UserView
pub fn trusted_user_view(&self, user: &impl AuthUser) -> UserView
Project trusted adapter output without removing declared hidden fields. Canonical identity accessors still refer to the physical model.
Sourcepub fn filter_user_record(
&self,
record: AdapterRecord<S::User>,
) -> AdapterRecord<S::User>
pub fn filter_user_record( &self, record: AdapterRecord<S::User>, ) -> AdapterRecord<S::User>
Preserve the initialized adapter result’s physical authority and declared undefined presence while applying the public user field policy once.
Sourcepub fn account_view(
&self,
account: &impl AuthAccount,
) -> AuthResult<Map<String, Value>>
pub fn account_view( &self, account: &impl AuthAccount, ) -> AuthResult<Map<String, Value>>
Public account output retains declared adapter projections and always removes credentials, including explicitly returned additional fields.
§Errors
Returns an error when the canonical account view cannot be serialized.
pub fn session_view(&self, session: &impl AuthSession) -> SessionView
pub fn trusted_session_view(&self, session: &impl AuthSession) -> SessionView
pub fn invitation_view( &self, invitation: &impl AuthInvitation, ) -> InvitationView
Sourcepub fn email_provider(&self) -> AuthResult<&dyn EmailProvider>
pub fn email_provider(&self) -> AuthResult<&dyn EmailProvider>
Get the email provider, returning an error if none is configured.
§Errors
Returns a configuration error if no email provider is configured.
Sourcepub fn session_manager(&self) -> SessionManager<S>
pub fn session_manager(&self) -> SessionManager<S>
Create a SessionManager from this context’s config and database.
Sourcepub async fn require_session(
&self,
req: &impl SessionRequest,
) -> AuthResult<(S::User, SessionView)>
pub async fn require_session( &self, req: &impl SessionRequest, ) -> AuthResult<(S::User, SessionView)>
Extract a session token from the request, validate the session, and
return the authenticated (User, Session) pair.
This centralises the pattern previously duplicated across many plugins
(get_authenticated_user, require_session, etc.).
§Errors
Returns an authentication error for a missing or invalid session, or propagates storage errors.
Sourcepub async fn require_cached_session(
&self,
req: &impl SessionRequest,
) -> AuthResult<(AuthenticatedUser<S>, SessionView)>
pub async fn require_cached_session( &self, req: &impl SessionRequest, ) -> AuthResult<(AuthenticatedUser<S>, SessionView)>
Read an ordinary HTTP session from the configured cache or storage. Sensitive stateful operations must continue using the physical APIs. Nested source get-session errors become an unauthenticated session; errors from later application/store operations are not caught here.
§Errors
Returns an error if the request has no valid session or session lookup fails.
Sourcepub async fn require_cached_session_strict(
&self,
req: &impl SessionRequest,
) -> AuthResult<(AuthenticatedUser<S>, SessionView)>
pub async fn require_cached_session_strict( &self, req: &impl SessionRequest, ) -> AuthResult<(AuthenticatedUser<S>, SessionView)>
Read an ordinary HTTP session from the configured cache or storage for
an application route. Unlike Self::require_cached_session, which
mirrors upstream’s nested get-session and answers every failure with
Unauthenticated, only a missing or invalid session (including a
malformed cache cookie) is Unauthenticated here.
§Errors
Returns Unauthenticated without a valid session, and propagates
storage and callback errors.
Sourcepub async fn require_session_with_refresh_state(
&self,
req: &impl SessionRequest,
) -> AuthResult<(S::User, SessionView, Option<bool>)>
pub async fn require_session_with_refresh_state( &self, req: &impl SessionRequest, ) -> AuthResult<(S::User, SessionView, Option<bool>)>
Authorize once and retain the optional deferred-refresh response field. Payload callbacks can observe the same context as nested session middleware without issuing another session read or refresh.
§Errors
Returns an authentication error for a missing or invalid session, or propagates storage errors.
Authoritative session authority without reconstructing an application model from a cookie. Stateless deployments authorize the authenticated cache snapshot; stateful deployments always bypass it.
Authorize against the persisted signed-cookie session. This bypasses hook-provided virtual sessions while preserving normal refresh, browser preferences and deferred-read behavior.
§Errors
Returns an authentication error if no valid persisted session exists, or propagates storage errors.
Resolve physical signed-cookie authority while retaining the actual initialized adapter output for downstream public and callback projections.
§Errors
Propagates authentication, storage and output callback failures.
Sourcepub async fn session_user(
&self,
session: &impl AuthSession,
) -> AuthResult<Option<S::User>>
pub async fn session_user( &self, session: &impl AuthSession, ) -> AuthResult<Option<S::User>>
Resolve the actual owner snapshot belonging to a stored session credential. Secondary-backed sessions retain their cached user; combined fallback uses SQL.
§Errors
Propagates backend failures and rejects mismatched cached ownership.
Sourcepub async fn session_without_refresh(
&self,
req: &impl SessionRequest,
) -> AuthResult<Option<(S::User, SessionView)>>
pub async fn session_without_refresh( &self, req: &impl SessionRequest, ) -> AuthResult<Option<(S::User, SessionView)>>
Read the request’s established session without extending its lifetime. Before hooks can establish a virtual session; otherwise a signed cookie must identify the persistent session.
§Errors
Propagates errors from session or user lookups.
Sourcepub async fn persistent_session(
&self,
req: &impl SessionRequest,
) -> AuthResult<Option<(S::User, SessionView)>>
pub async fn persistent_session( &self, req: &impl SessionRequest, ) -> AuthResult<Option<(S::User, SessionView)>>
Inspect a signed-cookie session without treating a missing login as an error.
§Errors
Propagates errors from session or user lookups.