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
Addallauth.mfa to your INSTALLED_APPS in settings.py:
settings.py
Basic Setup
The default configuration enables TOTP and recovery codes:settings.py
settings.py
URL Configuration
Include MFA URLs in your project’surls.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
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:- User enters their username and password
- User is prompted for their second factor (TOTP code, WebAuthn, or recovery code)
- Upon successful authentication, user gains access to their account
Development Setup
For local development with WebAuthn:settings.py
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 addingallauth.mfa to INSTALLED_APPS, run migrations:
Authenticator model which stores MFA credentials for users.