Technical Insights

How to Integrate Social Login (Google & Facebook) in Django

By Abishek Khawas • Oct 27, 2025
Integrating social login with Django lets users sign in using their existing Google or Facebook accounts—reducing friction, boosting signup rates, and making your app more user-friendly. This tutorial walks you through a clean implementation using the popular library django‑allauth (though you could also use alternatives). Why Use Social Login? Users avoid creating new credentials, which means less abandonment during signup. You offload authentication mechanics (password resets, email verification) to trusted platforms. It improves user experience and keeps your signup flow modern. Prerequisites Make sure: You have a Django project up and running. You’re comfortable editing settings.py, urls.py, and templates. You have developer accounts for Google Cloud Console and Facebook Developers to obtain client IDs and secrets. Step 1: Install & Configure django-allauth Install the library: pip install django-allauth In settings.py, add to INSTALLED_APPS: INSTALLED_APPS = [ # … your existing apps … 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.google', 'allauth.socialaccount.providers.facebook', ] SITE_ID = 1 Add authentication backends: AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'allauth.account.auth_backends.AuthenticationBackend', ) Configure redirect URLs: LOGIN_REDIRECT_URL = '/' ACCOUNT_LOGOUT_REDIRECT_URL = '/' Step 2: Set Up Social Providers (Google & Facebook) Google Go to Google Cloud Console → APIs & Services → Credentials. Create an OAuth 2.0 Client ID (Web Application). Add the “Authorized redirect URI” such as: https://yourdomain.com/accounts/google/login/callback/. Copy the Client ID and Secret. In settings.py, add: SOCIALACCOUNT_PROVIDERS = { 'google': { 'SCOPE': ['profile', 'email'], 'AUTH_PARAMS': {'access_type': 'online'} }, } Facebook Go to Facebook Developers → Create App → Set up Facebook Login. Add redirect URI like: https://yourdomain.com/accounts/facebook/login/callback/. In settings.py add: SOCIALACCOUNT_PROVIDERS['facebook'] = { 'METHOD': 'oauth2', 'SCOPE': ['email'], 'FIELDS': ['id', 'name', 'email'], } Step 3: Add URLs and Templates In your project’s urls.py add: from django.urls import path, include urlpatterns = [ # … other URLs … path('accounts/', include('allauth.urls')), ] In a template (e.g., login.html), add buttons: {% load socialaccount %} Login with Google Login with Facebook Step 4: Run Migrations & Test python manage.py migrate Visit http://yourdomain.com/accounts/login/ → You should see options to log in with Google and Facebook. Test the flow: selecting a provider prompts login, then returns the user to your site and creates/authenticates the user in Django. Step 5: Points to Remember / Best Practices Ensure the redirect URIs in Google/Facebook match exactly what you configured in Django. Mistakes here often cause errors. Make sure SITE_ID corresponds to the site entry in Django Admin /admin/sites/. Use HTTPS in production—OAuth providers often require secure URLs. For advanced use (REST API, mobile app, React/Vue front-end) consider libraries like dj‑rest‑auth or drf‑social‑oauth2. 💡 Final Thought By integrating Google and Facebook login into your Django app, you remove friction for your users and upgrade your authentication architecture with minimal extra work. Using django-allauth keeps things clean and extensible. Once set up, you can expand to other providers (GitHub, Twitter) seamlessly.