What is Social Authentication?
A third-party (“social”) account is a user account where authentication is delegated to an external identity provider like Google, GitHub, or Facebook. Theallauth.socialaccount app provides comprehensive support for managing social authentication in your Django application.
Key Features
Multiple Providers
Support for 100+ authentication providers including OAuth, OAuth2, OIDC, and SAML
Account Linking
Connect one or more social accounts to a local user account
Auto Signup
Optional instant signup for social accounts - no signup form required
Flexible Configuration
Configure providers via Django admin or settings.py
Core Capabilities
Social Account Management
- Connect Multiple Accounts: Users can link multiple social providers to a single local account
- Disconnect Accounts: Users can remove social account connections (requires setting a password if only the local account remains)
- Account Merging: Automatically merge social accounts with existing local accounts based on verified email addresses
Authentication Protocols
django-allauth supports all major authentication protocols:- OAuth 1.0a: Legacy OAuth protocol (Twitter, Flickr)
- OAuth 2.0: Modern OAuth standard (Google, GitHub, Facebook)
- OpenID Connect: Identity layer built on OAuth 2.0
- SAML 2.0: Enterprise SSO protocol
Installation
To use social authentication, install thesocialaccount extras:
Quick Start
1. Add to INSTALLED_APPS
Add the socialaccount app and your desired providers toINSTALLED_APPS:
2. Run Migrations
3. Configure a Provider
Configure your first provider insettings.py:
4. Add URLs
The allauth URLs are typically included automatically, but ensure they’re in yoururls.py:
5. Add Login Links
In your templates, add social login links:Data Models
django-allauth uses several models to manage social accounts:SocialApp
Stores provider configuration including:provider: Provider type (e.g., “google”, “github”)provider_id: For subproviders (OIDC, SAML)client_id: OAuth client ID or app IDsecret: Client secret or consumer secretsettings: JSON field for provider-specific settings
SocialAccount
Links users to their social accounts:user: Foreign key to your User modelprovider: Provider identifieruid: Unique identifier from the providerextra_data: JSON field storing profile data from the providerlast_login: Timestamp of last login
SocialToken
Stores OAuth tokens (whenSOCIALACCOUNT_STORE_TOKENS is enabled):
account: Foreign key to SocialAccounttoken: Access tokentoken_secret: Refresh token (OAuth2) or token secret (OAuth1)expires_at: Token expiration timestamp
Authentication Flow
- User Initiates Login: User clicks a social login link
- Redirect to Provider: User is redirected to the provider’s authorization page
- User Authorizes: User grants permissions to your application
- Callback: Provider redirects back with authorization code
- Token Exchange: Your app exchanges the code for an access token
- Fetch Profile: Your app retrieves user profile data
- Account Lookup: System checks if social account exists
- Create or Link: New account is created or linked to existing user
- Login: User is authenticated and logged in
Common Use Cases
Social-Only Authentication
Disable local accounts entirely:Auto-Signup
Bypass signup forms when possible:Email-Based Account Matching
Automatically link accounts with matching verified emails:Store OAuth Tokens
Save access tokens for making API calls:Security Considerations
POST for Login: For security, social login endpoints should require POST requests. Avoid enabling
SOCIALACCOUNT_LOGIN_ON_GET unless necessary.Next Steps
Configuration
Learn about all available settings and configuration options
Providers
Explore the 100+ supported authentication providers
Advanced Usage
Customize adapters, scopes, and provider behavior
