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: MetadataMapImplementations§
Source§impl<S: AuthSchema> AuthContext<S>
impl<S: AuthSchema> AuthContext<S>
Sourcepub fn error_page_response(
&self,
request: &AuthRequest,
) -> AuthResult<AuthResponse>
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>
impl<S: AuthSchema> AuthContext<S>
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: MetadataMap, ) -> Self
pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn get_metadata(&self, key: &str) -> Option<&Value>
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.
Sourcepub fn store_capabilities(&self) -> StoreCapabilities
pub fn store_capabilities(&self) -> StoreCapabilities
Explicit application storage configuration; adapter wrappers do not establish authority.
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 fn adapter_user_fields(&self) -> &UserConfig
pub fn adapter_user_fields(&self) -> &UserConfig
User policy used by the adapter before public output filtering.
Sourcepub async fn user_view(&self, user: &impl AuthUser) -> AuthResult<UserView>
pub async fn user_view(&self, user: &impl AuthUser) -> AuthResult<UserView>
Project a user through the active user schema before returning public data.
Sourcepub async fn internal_user_view(
&self,
user: &impl AuthUser,
) -> AuthResult<UserView>
pub async fn internal_user_view( &self, user: &impl AuthUser, ) -> AuthResult<UserView>
Keep hidden user fields available to trusted callbacks.
Sourcepub async fn session_view(
&self,
session: &impl AuthSession,
) -> AuthResult<SessionView>
pub async fn session_view( &self, session: &impl AuthSession, ) -> AuthResult<SessionView>
Preserve cached session fields without repeating database output transforms.
Sourcepub fn parse_user_input(
&self,
input: &Map<String, Value>,
create: bool,
) -> AuthResult<FieldMap>
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.
Sourcepub async fn require_session(
&self,
req: &AuthRequest,
) -> AuthResult<(UserView, SessionView)>
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.).
Require a session read from the server store for sensitive work.
Source§impl<S: AuthSchema> AuthContext<S>
impl<S: AuthSchema> AuthContext<S>
Sourcepub fn current_request_context(&self) -> Option<Arc<Self>>
pub fn current_request_context(&self) -> Option<Arc<Self>>
Resolve the context active for this auth instance, if one is in scope.
pub fn is_origin_trusted(&self, origin: &str) -> bool
pub fn is_redirect_target_trusted(&self, target: &str) -> bool
Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
Full resolved authentication URL, including its effective routing path.
Sourcepub fn base_path(&self) -> &str
pub fn base_path(&self) -> &str
Route prefix from the resolved URL, including a configured URL path.
pub fn trusted_origins(&self) -> &[String]
pub fn trusted_providers(&self) -> &[String]
Sourcepub async fn initialize_request_context(&self) -> AuthResult<Arc<Self>>
pub async fn initialize_request_context(&self) -> AuthResult<Arc<Self>>
Initialize options once for this auth instance before plugin setup or native use.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub async fn csrf_trusted_origins(
&self,
request: &AuthRequest,
) -> AuthResult<Vec<String>>
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>
impl<S: AuthSchema> AuthContext<S>
Sourcepub 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,
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.
Sourcepub 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,
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.