Skip to main content

Adapter Customization

The social account adapter allows you to customize core behaviors throughout the authentication flow. Create a custom adapter by subclassing DefaultSocialAccountAdapter.

Creating a Custom Adapter

myapp/adapters.py:
settings.py:

User Creation and Population

Control Signup Availability

Restrict signups based on provider, domain, or other criteria:

Custom User Field Mapping

Map provider-specific data to user fields:

Auto-Assign Roles Based on Provider

Custom Redirects

Provider-Specific Redirects

Dynamic Redirects Based on User Type

Customizing Provider Scopes

Request Additional Scopes

Most providers support custom scopes for accessing additional data:

Finding Default Scopes

To find the default scopes for a provider:
  1. Look in allauth/socialaccount/providers/<provider>/provider.py
  2. Find the get_default_scope(self) method
Example for Google:

Dynamic Scopes

Request different scopes based on context:

Customizing Providers

Subclass an Existing Provider

Create a custom provider variant: myapp/providers/google_custom/provider.py:
myapp/providers/google_custom/urls.py:
settings.py:

Override Provider URLs

Customize the provider URLs:

Authentication Parameters

OAuth2 Authentication Parameters

Pass additional parameters to the authorization endpoint:

Dynamic Auth Parameters

Set parameters dynamically:

Working with OAuth Tokens

Enable Token Storage

Retrieve Access Tokens

Make API Calls

Refresh Tokens

Email Verification

Trust Provider Email Verification

Mark emails from specific providers as verified:

Custom Email Verification Logic

Signals and Hooks

django-allauth provides signals for hooking into the authentication flow:

Available Signals

Prevent Login Based on Criteria

Multi-Tenant Support

Using Django Sites Framework

Configure different apps per site:
Create separate SocialApp instances via admin and assign to different sites.

Custom Tenant Logic

Security Best Practices

Require HTTPS

Limit Email Authentication

Require POST for Login

Enable PKCE for OAuth2

Next Steps

Providers

Browse all 100+ supported providers

Configuration

Complete settings reference