skip to navigation
skip to content

django-allauth-2fa 0.4.4

Adds two factor authentication to django-allauth

django-allauth-2fa adds two-factor authentication to django-allauth, a set of Django applications which help with authentication, registration, and other account management tasks.



Install django-allauth-2fa with pip (note that this will install Django, django-allauth, django-otp, qrcode and all of their requirements):

pip install django-allauth-2fa

After all the pre-requisities are installed, django-allauth and django-otp must be configured in your Django settings file. (Please check the django-allauth documentation and django-otp documentation for more in-depth steps on their configuration.)

    # Required by allauth.

    # Configure Django auth package.

    # Enable allauth.

    # Configure the django-otp package.

    # Enable two-factor auth.

    # Configure Django auth package.

    # Configure the django-otp package. Note this must be after the
    # AuthenticationMiddleware.

    # Reset login flow middleware. If this middleware is included, the login
    # flow is reset if another page is loaded between login and successfully
    # entering two-factor credentials.

# Set the allauth adapter to be the 2FA adapter.
ACCOUNT_ADAPTER = 'allauth_2fa.adapter.OTPAdapter'

# Configure your default site. See

After the above is configure, you must run migrations.

python migrate

Finally, you must include the django-allauth-2fa URLs:

from django.conf.urls import include, url

urlpatterns = [
    # Include the allauth and 2FA urls from their respective packages.
    url(r'^', include('allauth_2fa.urls')),
    url(r'^', include('allauth.urls')),


Any login view that is not provided by django-allauth will bypass the allauth workflow (including two-factor authentication). The Django admin site includes an additional login view (usually available at /admin/login).

The easiest way to fix this is to wrap it in login_required decorator (the code only works if you use the standard admin site, if you have a custom admin site you’ll need to customize this more):

from django.contrib import admin
from django.contrib.auth.decorators import login_required

# Ensure users go through the allauth workflow when logging into admin. = login_required(
# Run the standard admin set-up.


django-allauth-2fa was initially created by Víðir Valberg Guðmundsson (@valberg), and is currently maintained by Percipient Networks. Please feel free to contribute if you find django-allauth-2fa useful!

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. If you feel uncomfortable or uncertain about an issue or your changes, feel free to email and we will happily help you.
  3. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  4. Write a test which shows that the bug was fixed or that the feature works as expected.
  5. Send a pull request and bug the maintainer until it gets merged and published.

The test project can be used as a minimal example using the following:

# Run the server with debug.
DJANGO_SETTINGS_MODULE=tests.run_settings python runserver_plus
# Run the shell.
DJANGO_SETTINGS_MODULE=tests.run_settings python shell_plus
File Type Py Version Uploaded on Size
django_allauth_2fa-0.4.4-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2017-03-24 16KB