Skip to main content

Overview

django-allauth provides class-based views for all MFA workflows including TOTP, WebAuthn, and recovery codes. These views can be used directly or subclassed for customization.

Base MFA Views

AuthenticateView

Source: allauth/mfa/base/views.py:28 Handles MFA authentication during login. URL Name: mfa_authenticate Template: mfa/authenticate.html Form Classes:
  • AuthenticateForm - For TOTP/recovery codes
  • AuthenticateWebAuthnForm - For WebAuthn
Decorators: @login_stage_required(stage=AuthenticateStage.key) Context:
  • form - The authentication form
  • webauthn_form - WebAuthn form (if enabled)
  • js_data - JavaScript data for WebAuthn (request options)
  • MFA_SUPPORTED_TYPES - List of enabled MFA types

ReauthenticateView

Source: allauth/mfa/base/views.py:117 Handles MFA re-authentication for sensitive operations. URL Name: mfa_reauthenticate Template: mfa/reauthenticate.html Form Class: ReauthenticateForm Decorators: @login_required

IndexView

Source: allauth/mfa/base/views.py:138 Displays MFA management dashboard showing all configured authenticators. URL Name: mfa_index Template: mfa/index.html Decorators: @login_required Context:
  • authenticators - Dictionary of authenticators by type
  • MFA_SUPPORTED_TYPES - List of enabled MFA types
  • is_mfa_enabled - Boolean indicating if user has MFA

TrustView

Source: allauth/mfa/base/views.py:163 Allows users to trust a browser/device to skip MFA for a period. URL Name: mfa_trust Template: mfa/trust.html Decorators: @login_stage_required(stage=TrustStage.key) Context:
  • trust_from - Current timestamp
  • trust_until - When trust expires

TOTP Views

ActivateTOTPView

Source: allauth/mfa/totp/views.py:24 Handles TOTP authenticator activation with QR code display. URL Name: mfa_activate_totp Template: mfa/totp/activate_form.html Form Class: ActivateTOTPForm Decorators:
  • @redirect_if_add_not_allowed
  • @reauthentication_required
Context:
  • form - Activation form with secret field
  • totp_svg - SVG markup for QR code
  • totp_svg_data_uri - Data URI for QR code image
  • totp_url - Raw otpauth:// URL
Success URL: mfa_view_recovery_codes (if generated) or mfa_index

DeactivateTOTPView

Source: allauth/mfa/totp/views.py:75 Handles TOTP authenticator deactivation. URL Name: mfa_deactivate_totp Template: mfa/totp/deactivate_form.html Form Class: DeactivateTOTPForm Decorators: @login_required, @reauthentication_required Success URL: mfa_index

WebAuthn Views

AddWebAuthnView

Source: allauth/mfa/webauthn/views.py:31 Handles adding new WebAuthn credentials (security keys, biometrics). URL Name: mfa_add_webauthn Template: mfa/webauthn/add_form.html Form Class: AddWebAuthnForm Decorators:
  • @redirect_if_add_not_allowed
  • @reauthentication_required
Context:
  • form - Add form
  • js_data - JavaScript data with creation_options for WebAuthn API
Success URL: mfa_view_recovery_codes (if generated) or mfa_index

ListWebAuthnView

Source: allauth/mfa/webauthn/views.py:65 Lists all WebAuthn authenticators for the user. URL Name: mfa_list_webauthn Template: mfa/webauthn/authenticator_list.html Decorators: @login_required Context:
  • authenticators - QuerySet of WebAuthn authenticators

EditWebAuthnView

Source: allauth/mfa/webauthn/views.py:163 Allows renaming WebAuthn authenticators. URL Name: mfa_edit_webauthn Template: mfa/webauthn/edit_form.html Form Class: EditWebAuthnForm Decorators: @reauthentication_required Success URL: mfa_list_webauthn

RemoveWebAuthnView

Source: allauth/mfa/webauthn/views.py:81 Handles WebAuthn authenticator removal. URL Name: mfa_remove_webauthn Template: mfa/webauthn/authenticator_confirm_delete.html Decorators: @reauthentication_required Success URL: mfa_list_webauthn

LoginWebAuthnView

Source: allauth/mfa/webauthn/views.py:103 Handles passwordless WebAuthn login. URL Pattern: /accounts/webauthn/login/ Form Class: LoginWebAuthnForm Note: Only available if MFA_PASSKEY_LOGIN_ENABLED = True

ReauthenticateWebAuthnView

Source: allauth/mfa/webauthn/views.py:131 Handles re-authentication using WebAuthn. URL Name: mfa_reauthenticate_webauthn Template: mfa/webauthn/reauthenticate.html Form Class: ReauthenticateWebAuthnForm Context:
  • form - Re-authentication form
  • js_data - JavaScript data with request_options

SignupWebAuthnView

Source: allauth/mfa/webauthn/views.py:183 Handles WebAuthn credential creation during signup. URL Name: mfa_signup_webauthn Template: mfa/webauthn/signup_form.html Form Class: SignupWebAuthnForm Decorators: @login_stage_required(stage=PasskeySignupStage.key) Note: Only available if MFA_PASSKEY_SIGNUP_ENABLED = True

Recovery Codes Views

GenerateRecoveryCodesView

Source: allauth/mfa/recovery_codes/views.py:19 Generates new recovery codes (regenerates if they already exist). URL Name: mfa_generate_recovery_codes Template: mfa/recovery_codes/generate.html Form Class: GenerateRecoveryCodesForm Decorators: @reauthentication_required Success URL: mfa_view_recovery_codes Context:
  • form - Generation form
  • unused_code_count - Number of unused codes (before regeneration)

ViewRecoveryCodesView

Source: allauth/mfa/recovery_codes/views.py:83 Displays recovery codes to the user. URL Name: mfa_view_recovery_codes Template: mfa/recovery_codes/index.html Decorators: @login_required Context:
  • unused_codes - List of unused recovery codes
  • total_count - Total number of codes

DownloadRecoveryCodesView

Source: allauth/mfa/recovery_codes/views.py:55 Provides recovery codes as a downloadable text file. URL Name: mfa_download_recovery_codes Template: mfa/recovery_codes/download.txt Content Type: text/plain Decorators: @login_required, @never_cache Response Headers:

View Customization Examples

Custom TOTP Activation with Email Notification

Custom WebAuthn List with Filtering

Custom MFA Index with Analytics

URL Configuration

Form Override Configuration