Skip to main content
The allauth.mfa app provides comprehensive multi-factor authentication (MFA) functionality for django-allauth, supporting multiple authentication methods to enhance account security.

Features

django-allauth MFA includes support for:
  • TOTP Authentication - Time-based One-Time Password authentication using authenticator apps
  • WebAuthn/FIDO2 - Hardware security keys and biometric authentication
  • Passkey Login - Passwordless authentication using WebAuthn
  • Recovery Codes - Backup codes for account recovery when primary methods are unavailable
  • Browser Trust - Optional “trust this browser” functionality to reduce friction

Installation

Install django-allauth with MFA support:
The [mfa] extra installs additional dependencies required for MFA functionality, including qrcode for TOTP QR codes and fido2 for WebAuthn support.

Configuration

Add allauth.mfa to your INSTALLED_APPS in settings.py:
settings.py

Basic Setup

The default configuration enables TOTP and recovery codes:
settings.py
To enable WebAuthn support:
settings.py

URL Configuration

Include MFA URLs in your project’s urls.py:
urls.py
MFA URLs are automatically included when you include allauth.urls. The URLs are available at /accounts/mfa/.

Email Verification Requirement

By default, users must verify their email address before enabling MFA. This prevents attackers from locking out legitimate account owners:
settings.py
Setting MFA_ALLOW_UNVERIFIED_EMAIL = True allows attackers to sign up with someone else’s email and enable MFA, potentially locking out the legitimate owner. Only enable this if you understand the security implications.

Available MFA Types

TOTP (Time-based One-Time Password)

Users can set up TOTP authentication using authenticator apps like Google Authenticator, Authy, or 1Password. Learn more about TOTP setup →

WebAuthn

Support for FIDO2 security keys, platform authenticators (like Touch ID/Face ID), and passkeys. Learn more about WebAuthn →

Recovery Codes

Backup codes that users can use if they lose access to their primary authentication method. Learn more about recovery codes →

User Flow

When a user has MFA enabled:
  1. User enters their username and password
  2. User is prompted for their second factor (TOTP code, WebAuthn, or recovery code)
  3. Upon successful authentication, user gains access to their account

Development Setup

For local development with WebAuthn:
settings.py
Never set MFA_WEBAUTHN_ALLOW_INSECURE_ORIGIN = True in production. This setting bypasses important security checks.

Next Steps

TOTP Setup

Configure time-based one-time passwords

WebAuthn

Set up hardware keys and passkeys

Recovery Codes

Implement backup authentication codes

Database Migrations

After adding allauth.mfa to INSTALLED_APPS, run migrations:
This creates the Authenticator model which stores MFA credentials for users.