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:- Email Only
- Username Only
- Email or Username
- Phone Number
forms.py:75):Login by Code (Magic Link)
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):
- 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):
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:The Signup Flow
Complete Signup Process
Enumeration Prevention
django-allauth prevents this by default:- Signup
- Password Reset
- Strict Mode
When
ACCOUNT_EMAIL_VERIFICATION = "mandatory":- User signs up with email already in use
- No error shown to user
- System sends “account already exists” email to that address
- User sees same “check your email” message
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
- Link-Based (Default)
- Code-Based
User receives email with a link containing a token.Token Generator:The default token generator includes email addresses in the hash, so the token becomes invalid if the user’s email changes:From source (
forms.py:39-49):Custom Token Generator
Implement custom password reset token logic:Login State Management
The Login Model
From source (models.py):
- Which user is logging in (or
Noneif 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
nextparameter in URL:?next=/profile/- Adapter’s
get_login_redirect_url()method LOGIN_REDIRECT_URLsetting
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: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
