Skip to main content

Overview

Multi-Factor Authentication (MFA) adds an additional security layer to your app by requiring users to provide two forms of verification. The Dynamic Swift SDK supports:
  • TOTP (Time-based One-Time Password) - Codes from authenticator apps like Google Authenticator or Authy
  • Passkey MFA - Biometric authentication as a second factor
  • Recovery Codes - Backup codes for account recovery
MFA must be enabled in your Dynamic Dashboard under Security settings before you can use it in your app.

Prerequisites

  • Dynamic SDK initialized (see Installation Guide)
  • User must be authenticated
  • MFA enabled in your Dynamic dashboard
  • iOS 15.5+ (iOS 16.0+ for passkey support)

MFA Device Management

Get User’s MFA Devices

Fetch all MFA devices registered for the current user:

Add a New TOTP Device

Register a new TOTP device (authenticator app):

Verify a New Device

After adding a device, verify it with a TOTP code from your authenticator app:

Authenticate with an Existing Device

Authenticate with an existing MFA device to get an MFA token:

Delete an MFA Device

Remove an MFA device from the user’s account:

Recovery Codes

Get Recovery Codes

After setting up MFA, users should save recovery codes for account recovery:

Acknowledge Recovery Codes

After displaying recovery codes to the user, you should acknowledge that they’ve been shown:
Recovery Code Flow: When a user sets up MFA for the first time, they’ll receive recovery codes. The app should:
  1. Display all recovery codes clearly
  2. Prompt the user to save them securely
  3. Call acknowledgeRecoveryCodes() once the user confirms they’ve saved them
  4. Store the acknowledgment state to prevent showing codes repeatedly

Generate New Recovery Codes

If recovery codes are lost or compromised:

Use Recovery Code for Authentication

If user loses their device, they can use a recovery code:

Passkey MFA

Use passkeys as a second factor for enhanced security. Passkeys provide a seamless biometric authentication experience.
Configuration Required: Before using passkeys for MFA, you must configure associated domains and the SDK. See the Passkey Setup Guide for complete configuration instructions.

Register Passkey as MFA Device

After initial authentication, users can register a passkey as an additional MFA method:
Passkey Advantages: Passkeys offer several benefits over TOTP:
  • No need for a separate authenticator app
  • Biometric authentication (Face ID / Touch ID)
  • More secure against phishing
  • Faster authentication flow

Complete SwiftUI Example

Here’s a complete MFA management interface:

Best Practices

1. User Experience

  • Clear instructions: Guide users through the setup process
  • QR code display: Make QR codes large and easy to scan
  • Recovery codes: Emphasize the importance of saving recovery codes
  • Multiple devices: Allow users to add multiple authenticator apps

2. Security

  • Require MFA for sensitive actions: Prompt for MFA when deleting accounts, changing settings, or performing financial transactions
  • Single-use tokens: Use singleUse: true for sensitive operations
  • Recovery code limits: Each recovery code can only be used once

3. Error Handling

Troubleshooting

Code Not Working

  • Time sync: Ensure device time is synchronized (TOTP codes are time-based)
  • Code expired: TOTP codes expire every 30 seconds
  • Wrong device: Verify the correct authenticator app is being used

Can’t Delete Last Device

  • Users must keep at least one MFA method or disable MFA entirely
  • Consider implementing an admin reset flow

Recovery Codes Not Showing

  • Recovery codes are only available after a device is authenticated
  • User must authenticate with TOTP code first

Next Steps

Now that you have MFA set up, you can:
  1. Passkey Setup - Configure passkeys for 1FA sign-in or MFA
  2. Wallet Operations - Perform wallet operations
  3. Session Management - Manage authenticated sessions
The Swift ExampleApp includes a complete MFA implementation with device management, recovery codes, and passkey integration. See swift-sdk-and-sample-app/ExampleApp for the full code.
Last modified on April 3, 2026