pub enum AuthState {
Guest,
Identifying {
user_id: UserId,
tenant_id: TenantId,
},
Authenticating {
user_id: UserId,
tenant_id: TenantId,
method_name: Arc<str>,
remaining: Vec<FactorKind>,
completed: Vec<FactorKind>,
attempt_count: u32,
last_attempt: Option<DateTime<Utc>>,
},
Authenticated {
user_id: UserId,
tenant_id: TenantId,
authn_time: DateTime<Utc>,
factors_completed: Vec<FactorKind>,
},
PendingWorkflow {
user_id: UserId,
tenant_id: TenantId,
workflow: WorkflowState,
},
}Expand description
Authentication state machine: flat enum, typed UserId / TenantId IDs.
The state machine follows a strict forward progression with
PendingWorkflow as a post-authentication holding state.
§State transition diagram
┌───────────────────────────┐
│ (app-level, optional) │
Guest ─┬──────────►│ Identifying ──► Authenticating ──► Authenticated
│ └───────────────────────────┘ ▲
│ │
└──► Authenticating ──► Authenticated │
│ (begin_login default path) │
│ │
└──► PendingWorkflow(Signup) ──────────────────────┘
▲ (begin_signup) (complete_signup)
│ │
│ (logout / session clear) │
└───────────────────────────────────────────────────────-┘- Guest: anonymous visitor, no authentication started.
- Identifying: optional state for username-first flows. The built-in
AuthnService::begin_login()skips this and goes directly toAuthenticating. Available viasession.set_identifying()for apps that need a two-step identify-then-authenticate UX. - Authenticating: progressing through a multi-factor method;
remainingtracks which factor kinds are still to be verified. - Authenticated: all required factors verified; full access granted.
- PendingWorkflow: blocked on a post-auth step (signup, KYC, password
reset, etc.). Reached via
begin_signup()or app-level workflow initiation.
Calling AuthSession::clear from
any state resets the session back to Guest (logout).
Variants§
Guest
No authentication started; anonymous visitor.
Identifying
User identified (username entered), first factor not yet verified.
Fields
Authenticating
Progressing through a multi-factor method.
Fields
remaining: Vec<FactorKind>Ordered list of factor kinds still to be verified.
completed: Vec<FactorKind>Factor kinds that have already been verified in this flow,
in the order they were completed. Carried into
AuthState::Authenticated::factors_completed on transition
so audit events can record the full list.
Authenticated
All factors verified: user is fully authenticated.
Fields
factors_completed: Vec<FactorKind>Factor kinds that were verified to reach this state, in
completion order. Used by the audit log to distinguish
“user logged in with password only because the tenant
disables TOTP” (legitimate single-factor) from “user
reached Authenticated without verifying TOTP” (bypass
attack). Empty for sessions whose state predates this
field; serde(default) keeps existing serialized
sessions readable.
PendingWorkflow
Authenticated but blocked on a post-auth workflow (e.g. signup, KYC, password reset).
Implementations§
Source§impl AuthState
impl AuthState
Sourcepub fn user_id(&self) -> Option<&UserId>
pub fn user_id(&self) -> Option<&UserId>
Return the authenticated user ID if one is associated with this state.
Sourcepub fn tenant_id(&self) -> Option<&TenantId>
pub fn tenant_id(&self) -> Option<&TenantId>
Return the tenant ID if one is associated with this state.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Return true if this state represents a fully authenticated session.
Sourcepub fn is_authenticating(&self) -> bool
pub fn is_authenticating(&self) -> bool
Return true if the session is in progress through a multi-factor flow.
Use this to guard MFA factor-verification routes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AuthState
impl<'de> Deserialize<'de> for AuthState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for AuthState
Auto Trait Implementations§
impl Freeze for AuthState
impl RefUnwindSafe for AuthState
impl Send for AuthState
impl Sync for AuthState
impl Unpin for AuthState
impl UnsafeUnpin for AuthState
impl UnwindSafe for AuthState
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.