Skip to main content

AuthContext

Struct AuthContext 

Source
pub struct AuthContext<S: AuthSchema> {
    pub extensions: RuntimeExtensions,
    pub email_verification_policy: EmailVerificationRuntimePolicy,
    pub config: Arc<AuthConfig>,
    pub database: Arc<dyn AuthStore<S>>,
    pub email_provider: Option<Arc<dyn EmailProvider>>,
    pub secondary_storage: Option<Arc<dyn SecondaryStorage>>,
    pub password_policy: PasswordRuntimePolicy,
    pub metadata: MetadataMap,
    /* private fields */
}
Expand description

Context passed to plugin methods.

Fields§

§extensions: RuntimeExtensions§email_verification_policy: EmailVerificationRuntimePolicy§config: Arc<AuthConfig>§database: Arc<dyn AuthStore<S>>§email_provider: Option<Arc<dyn EmailProvider>>§secondary_storage: Option<Arc<dyn SecondaryStorage>>§password_policy: PasswordRuntimePolicy§metadata: MetadataMap

Implementations§

Source§

impl<S: AuthSchema> AuthContext<S>

Source

pub fn error_page_response( &self, request: &AuthRequest, ) -> AuthResult<AuthResponse>

Render /error from the original Request URL, including duplicate-query ordering.

Source§

impl<S: AuthSchema> AuthContext<S>

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: MetadataMap, ) -> 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 email_provider(&self) -> AuthResult<&dyn EmailProvider>

Get the email provider, returning an error if none is configured.

Source

pub fn store_capabilities(&self) -> StoreCapabilities

Explicit application storage configuration; adapter wrappers do not establish authority.

Source

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

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

Source

pub fn adapter_user_fields(&self) -> &UserConfig

User policy used by the adapter before public output filtering.

Source

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

Project a user through the active user schema before returning public data.

Source

pub async fn internal_user_view( &self, user: &impl AuthUser, ) -> AuthResult<UserView>

Keep hidden user fields available to trusted callbacks.

Source

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

Preserve cached session fields without repeating database output transforms.

Source

pub fn parse_user_input( &self, input: &Map<String, Value>, create: bool, ) -> AuthResult<FieldMap>

Validate public user fields, including proof and privilege fields owned by active plugins.

Source

pub async fn require_session( &self, req: &AuthRequest, ) -> AuthResult<(UserView, 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.).

Source

pub async fn require_authoritative_session( &self, req: &AuthRequest, ) -> AuthResult<(UserView, SessionView)>

Require a session read from the server store for sensitive work.

Source§

impl<S: AuthSchema> AuthContext<S>

Source

pub fn current_request_context(&self) -> Option<Arc<Self>>

Resolve the context active for this auth instance, if one is in scope.

Source

pub fn is_origin_trusted(&self, origin: &str) -> bool

Source

pub fn is_redirect_target_trusted(&self, target: &str) -> bool

Source

pub fn base_url(&self) -> &str

Full resolved authentication URL, including its effective routing path.

Source

pub fn base_path(&self) -> &str

Route prefix from the resolved URL, including a configured URL path.

Source

pub fn trusted_origins(&self) -> &[String]

Source

pub fn trusted_providers(&self) -> &[String]

Source

pub async fn initialize_request_context(&self) -> AuthResult<Arc<Self>>

Initialize options once for this auth instance before plugin setup or native use.

Source

pub async fn with_native_context<T, F, Fut>( &self, input: NativeRequest<'_>, operation: F, ) -> AuthResult<T>
where F: FnOnce(Arc<AuthContext<S>>) -> Fut + Send, Fut: Future<Output = AuthResult<T>> + Send, T: Send,

Resolve native URL policy and enter this auth instance’s runtime scope.

Source

pub async fn with_http_context<T, F, Fut>( &self, request: &AuthRequest, operation: F, ) -> AuthResult<T>
where F: FnOnce(Arc<AuthContext<S>>) -> Fut + Send, Fut: Future<Output = AuthResult<T>> + Send, T: Send,

Enter the HTTP policy branch before rate limiting, request hooks, and body decoding.

Source

pub async fn csrf_trusted_origins( &self, request: &AuthRequest, ) -> AuthResult<Vec<String>>

The origin middleware calls functional origins again after HTTP resolution.

Source§

impl<S: AuthSchema> AuthContext<S>

Source

pub async fn dispatch_native<F, Fut>( &self, source: NativeRequest<'_>, route: AuthRoute, body: Option<Value>, query: Option<Value>, handler: F, ) -> AuthResult<AuthResponse>
where F: FnOnce(AuthRequest, Arc<AuthContext<S>>) -> Fut + Send, Fut: Future<Output = AuthResult<AuthResponse>> + Send,

Invoke a native endpoint with the instance’s shared hook and validation pipeline.

Source

pub async fn dispatch_native_value<F, Fut>( &self, source: NativeRequest<'_>, route: AuthRoute, body: FieldValue, query: Option<Value>, handler: F, ) -> AuthResult<AuthResponse>
where F: FnOnce(AuthRequest, Arc<AuthContext<S>>) -> Fut + Send, Fut: Future<Output = AuthResult<AuthResponse>> + Send,

Invoke a native endpoint while retaining Date, undefined, and object identities.

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

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