Social Login with django-allauth
A snippet for adding social authentication to Django using django-allauth.
# settings.py
INSTALLED_APPS = [
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google', # or github, facebook, etc.
]
SITE_ID = 1
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
LOGIN_REDIRECT_URL = '/'
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_EMAIL_REQUIRED = True
# urls.py
from django.urls import path, include
urlpatterns = [
path('accounts/', include('allauth.urls')),
]
# templates/base.html
<a href="/accounts/google/login/">Login with Google</a>
<a href="/accounts/github/login/">Login with GitHub</a>
Explanation:
-
django-allauthhandles registration, login, logout, and social authentication with multiple providers. -
You need to enable providers like Google or GitHub in
INSTALLED_APPSand configure their API keys in the Django admin. -
/accounts/URL includes all views for signup, login, logout, and social redirects. -
Custom login links like
/accounts/google/login/redirect to the selected provider.
- Category Authentication & Authorization
- Total Views 554
- Last Modified 09 December, 2025
- Tags #social login #allauth #auth #oauth
Previous snippet
Limit Login Attempts
Next snippet