Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
npx @tessl/cli install tessl/pypi-django-allauth@65.11.0A comprehensive Django authentication library providing integrated local and social authentication, account management, multi-factor authentication, and headless API support. Django-allauth serves as a complete authentication solution for Django applications, supporting everything from basic login/registration to enterprise-grade authentication flows with 50+ social providers.
pip install django-allauthimport allauthCommon Django settings and URL configuration:
# settings.py
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.messages',
'allauth',
'allauth.account',
# Optional components
'allauth.socialaccount',
'allauth.mfa',
'allauth.headless',
'allauth.usersessions',
]
# urls.py
from django.urls import path, include
urlpatterns = [
path('accounts/', include('allauth.urls')),
]# Basic account setup
from allauth.account.models import EmailAddress
from allauth.account.adapter import get_adapter
from django.contrib.auth import get_user_model
User = get_user_model()
# Create user with email verification
adapter = get_adapter()
user = adapter.new_user(request)
adapter.save_user(request, user, form)
# Add and verify email
email_address = EmailAddress.objects.add_email(request, user, 'user@example.com')
email_address.send_confirmation(request)
# Social authentication setup
from allauth.socialaccount.models import SocialApp
# Configure social provider (e.g., Google)
google_app = SocialApp.objects.create(
provider='google',
name='Google OAuth2',
client_id='your-client-id',
secret='your-client-secret'
)Django-allauth follows Django's modular app architecture with several key components:
The library uses Django's adapter pattern for customization, comprehensive signal system for extensibility, and follows Django best practices for models, views, forms, and URL configuration.
Core configuration management, utility functions, and version information. Provides settings management, username generation, URL building, and other foundational functionality.
class AppSettings:
SITES_ENABLED: bool
SOCIALACCOUNT_ENABLED: bool
MFA_ENABLED: bool
HEADLESS_ENABLED: bool
def generate_unique_username(txts: list, regex: str = None) -> str: ...
def build_absolute_uri(request, location: str, protocol: str = None) -> str: ...
def import_attribute(path: str): ...Local user authentication, registration, email verification, password management, and account settings. Handles traditional Django authentication flows with enhanced email and phone verification.
class EmailAddress:
user: User
email: str
verified: bool
primary: bool
class LoginView(FormView): ...
class SignupView(FormView): ...
class PasswordResetView(FormView): ...
def get_adapter() -> AccountAdapter: ...OAuth 1.0/2.0 integration supporting 50+ providers including Google, Facebook, GitHub, Twitter, and enterprise providers. Provides complete social login flows with account linking capabilities.
class SocialApp:
provider: str
provider_id: str
client_id: str
secret: str
settings: dict
class SocialAccount:
user: User
provider: str
uid: str
extra_data: dict
def get_adapter() -> SocialAccountAdapter: ...TOTP authenticators, WebAuthn hardware keys, recovery codes, and MFA management flows. Provides enterprise-grade security with multiple authentication factor support.
class Authenticator:
user: User
type: str
data: dict
class RecoveryCode:
user: User
code: str
used_at: datetimeREST API endpoints for mobile and single-page applications. Provides JSON-based authentication flows without traditional Django templates and forms.
class Flow(str, Enum):
LOGIN = "login"
SIGNUP = "signup"
VERIFY_EMAIL = "verify_email"
PASSWORD_RESET_BY_CODE = "password_reset_by_code"
class Client(str, Enum):
APP = "app"
BROWSER = "browser"Multi-device session tracking, session metadata collection, and cross-device logout capabilities. Provides visibility and control over user sessions across different devices and browsers.
class UserSession:
user: User
ip: str
user_agent: str
created_at: datetime
last_seen_at: datetimeComprehensive template tag library with element-based UI framework, slot system for template composition, and customizable layouts for authentication UI.
@register.tag(name="element")
def do_element(parser, token): ...
@register.tag(name="slot")
def do_slot(parser, token): ...
@register.tag(name="setvar")
def do_setvar(parser, token): ...from typing import Optional, Dict, Any, List
from django.contrib.auth.models import AbstractUser
from django.http import HttpRequest
User = AbstractUser
class AccountAdapter:
def new_user(self, request: HttpRequest) -> User: ...
def save_user(self, request: HttpRequest, user: User, form) -> None: ...
def clean_username(self, username: str, shallow: bool = False) -> str: ...
class SocialAccountAdapter:
def new_user(self, request: HttpRequest, sociallogin) -> User: ...
def populate_user(self, request: HttpRequest, sociallogin, data: Dict[str, Any]) -> User: ...
class EmailConfirmation:
email_address: EmailAddress
created: datetime
sent: datetime
key: str