Skip to main content

Overview

django-allauth implements sophisticated authentication flows that handle complex multi-step processes. These flows coordinate between forms, adapters, models, and stages to provide secure, flexible authentication experiences.
Flows are internal orchestration logic in allauth.account.internal.flows that manage the complex dance between different authentication steps.

The Login Flow

Standard Login Process

Login Methods

django-allauth supports multiple login methods that can be mixed and matched:
Users log in with their email address and password. The login form shows an email field.From source (forms.py:75):
Passwordless authentication via one-time codes sent by email: Configuration:

Authentication Recording

django-allauth maintains a session log of all authentication methods used: From source (flows/login.py:19-57):
This enables:
  • Multi-factor authentication tracking
  • Step-up authentication
  • Security auditing
  • Conditional access based on authentication strength

Login Stages

Stages allow for multi-step login processes:

Email Verification Stage

From source (stages.py:130-148):
When a user with an unverified email tries to log in with ACCOUNT_EMAIL_VERIFICATION = "mandatory", they’re redirected to verify their email before fully logging in.

Login Stage Controller

From source (stages.py:56-118):

Login Timeout

Limit how long multi-step login can take:
This prevents users from starting login, getting stuck at MFA, and returning hours later. After timeout, they must start over.

The Signup Flow

Complete Signup Process

Enumeration Prevention

Enumeration attacks allow attackers to discover which email addresses have accounts by observing different responses for existing vs. non-existing emails.
django-allauth prevents this by default:
How it works:
When ACCOUNT_EMAIL_VERIFICATION = "mandatory":
  1. User signs up with email already in use
  2. No error shown to user
  3. System sends “account already exists” email to that address
  4. User sees same “check your email” message
✅ Attacker cannot tell if email was already registeredFrom source (configuration.rst:35-45):
Whether or not enumeration can be prevented during signup depends on the email verification method. In case of mandatory verification, enumeration can be properly prevented because the case where an email address is already taken is indistinguishable from the case where it is not.

Signup Hooks

Customize signup behavior with adapter hooks:

Password Reset Flow

Reset Process

Reset Methods

Custom Token Generator

Implement custom password reset token logic:

Login State Management

The Login Model

From source (models.py):
This model tracks:
  • Which user is logging in (or None if not yet authenticated)
  • What stages have been completed
  • Where to redirect after successful login
  • Whether this is a signup or regular login

Session Storage

Login state is stashed in the session during multi-step flows:

Redirects After Authentication

Login Redirects

Redirect priority:
  1. next parameter in URL: ?next=/profile/
  2. Adapter’s get_login_redirect_url() method
  3. LOGIN_REDIRECT_URL setting
Custom adapter:

Signup Redirects

Users are only redirected to SIGNUP_REDIRECT_URL if signup completed without interruptions (e.g., no email verification step).

Logout Redirects

Rate Limiting in Flows

Rate limits are enforced at key points in authentication flows:
From source (flows/login.py:120-127):

Advanced Flow Customization

Custom Login Flow

Custom Signup Flow

Next Steps

Email Verification

Deep dive into email verification flows and strategies

Rate Limiting

Configure rate limits to protect authentication endpoints