Skip to main content

AuthContext

Struct AuthContext 

Source
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: ContextExtensions

Implementations§

Source§

impl<S: AuthSchema> AuthContext<S>

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn with_metadata( config: Arc<AuthConfig>, database: Arc<dyn AuthStore<S>>, metadata: HashMap<String, Value>, ) -> Self

Source

pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)

Source

pub fn get_metadata(&self, key: &str) -> Option<&Value>

Source

pub fn with_extensions(self, extensions: ContextExtensions) -> Self

Source

pub fn email_verification_override( &self, ) -> Option<Arc<VerificationEmailOverrideHandle<S>>>

Source

pub fn user_view(&self, user: &impl AuthUser) -> UserView

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn trusted_session_view(&self, session: &impl AuthSession) -> SessionView

Source

pub fn invitation_view( &self, invitation: &impl AuthInvitation, ) -> InvitationView

Source

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.

Source

pub fn session_manager(&self) -> SessionManager<S>

Create a SessionManager from this context’s config and database.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn require_authoritative_cached_session( &self, req: &AuthRequest, ) -> AuthResult<(AuthenticatedUser<S>, SessionView)>

Authoritative session authority without reconstructing an application model from a cookie. Stateless deployments authorize the authenticated cache snapshot; stateful deployments always bypass it.

Source

pub async fn require_authoritative_session( &self, req: &impl SessionRequest, ) -> AuthResult<(S::User, SessionView)>

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.

Source

pub async fn require_authoritative_session_record( &self, req: &impl SessionRequest, ) -> AuthResult<(AdapterRecord<S::User>, SessionView)>

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.

Source

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.

Source

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.

Source

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.

Source§

impl<S: AuthSchema> AuthContext<S>

Trait Implementations§

Source§

impl<S: AuthSchema> Clone for AuthContext<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 AuthContext<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 AuthContext<S>

§

impl<S> !UnwindSafe for AuthContext<S>

§

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

§

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

§

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

§

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

§

impl<S> UnsafeUnpin for AuthContext<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