MfaManager

Struct MfaManager 

Source
pub struct MfaManager {
    pub totp: TotpManager,
    pub sms: SmsKitManager,
    pub email: EmailManager,
    pub backup_codes: BackupCodesManager,
    /* private fields */
}
Expand description

Centralized multi-factor authentication (MFA) manager.

MfaManager coordinates all MFA operations across different authentication factors including TOTP, SMS, email, and backup codes. It provides a unified interface for MFA setup, challenge generation, and verification while supporting multiple MFA methods simultaneously.

§Supported MFA Methods

  • TOTP (Time-based OTP): RFC 6238 compliant authenticator apps
  • SMS: Text message-based verification codes
  • Email: Email-based verification codes
  • Backup Codes: Single-use recovery codes

§Multi-Method Support

Users can enable multiple MFA methods simultaneously, providing flexibility and redundancy. The manager handles method coordination and fallback scenarios.

§Security Features

  • Challenge Expiration: Time-limited challenges prevent replay attacks
  • Rate Limiting: Prevents brute force attacks on MFA codes
  • Secure Code Generation: Cryptographically secure random code generation
  • Method Validation: Validates MFA setup before enabling
  • Audit Logging: Comprehensive logging of all MFA operations

§Cross-Method Operations

The manager supports advanced scenarios like:

  • Method fallback when primary method fails
  • Cross-method challenge validation
  • Method strength assessment
  • Risk-based MFA requirements

§Example

use auth_framework::auth_modular::mfa::MfaManager;

// Create MFA manager with storage backend
let mfa_manager = MfaManager::new(storage);

// Setup TOTP for a user
let setup_result = mfa_manager.totp.setup_totp("user123", "user@example.com").await?;

// Generate challenge
let challenge = mfa_manager.create_challenge("user123", MfaMethodType::Totp).await?;

// Verify user's response
let verification = mfa_manager.verify_challenge(&challenge.id, "123456").await?;

§Thread Safety

The MFA manager is designed for concurrent use and safely coordinates access to underlying MFA method implementations.

§Storage Integration

Integrates with the framework’s storage system to persist:

  • User MFA method configurations
  • Active challenges
  • Usage statistics and audit logs
  • Backup codes and secrets

Fields§

§totp: TotpManager

TOTP manager

§sms: SmsKitManager

SMS manager (using SMSKit)

§email: EmailManager

Email manager

§backup_codes: BackupCodesManager

Backup codes manager

Implementations§

Source§

impl MfaManager

Source

pub fn new(storage: Arc<dyn AuthStorage>) -> Self

Create a new MFA manager

Source

pub fn new_with_smskit_config( storage: Arc<dyn AuthStorage>, smskit_config: SmsKitConfig, ) -> Result<Self>

Create a new MFA manager with SMSKit configuration

Source

pub async fn store_challenge(&self, challenge: MfaChallenge) -> Result<()>

Store an MFA challenge

Source

pub async fn get_challenge( &self, challenge_id: &str, ) -> Result<Option<MfaChallenge>>

Get an MFA challenge

Source

pub async fn remove_challenge(&self, challenge_id: &str) -> Result<()>

Remove an MFA challenge

Source

pub async fn cleanup_expired_challenges(&self) -> Result<()>

Clean up expired challenges

Source

pub async fn get_active_challenge_count(&self) -> usize

Get count of active challenges

Source

pub async fn initiate_step_up_authentication( &self, user_id: &str, required_methods: &[MfaMethod], risk_level: RiskLevel, ) -> Result<CrossMethodChallenge>

MFA CROSS-METHOD OPERATIONS: Step-up authentication with multiple factors

Source

pub async fn complete_cross_method_step( &self, challenge_id: &str, method: MfaMethod, response: &str, ) -> Result<CrossMethodCompletionResult>

Complete a specific method within a cross-method challenge

Source

pub async fn get_available_methods( &self, user_id: &str, ) -> Result<Vec<MfaMethod>>

Get available MFA methods for a user

Source

pub async fn perform_method_fallback( &self, user_id: &str, failed_method: MfaMethod, fallback_order: &[MfaMethod], ) -> Result<MethodFallbackResult>

Perform method fallback when primary method fails

Source

pub async fn emergency_mfa_bypass( &self, user_id: &str, admin_token: &str, ) -> Result<bool>

Emergency MFA bypass using direct storage access This method provides a way to recover when all MFA methods fail

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> ErasedDestructor for T
where T: 'static,