Featured
Why Choose django-social-auth-rest for Social Login in Django
A plain-English comparison of social login options for Django. See why django-social-auth-rest is the fastest and simplest way to add Google and GitHub login to a Django REST API.
Social login - signing in with Google, GitHub, or another provider - has become something users expect. It removes the friction of creating yet another password, and it works on every device without extra setup.
But adding social login to a Django project is rarely as simple as it sounds. The moment you start building it, you hit a wall of decisions: Which library should I use? Do I need extra middleware? Will it work with my REST API? Does it play well with JWT tokens?
This post walks through the most common options Django developers reach for, and explains why django-social-auth-rest is the best fit if you are building an API-first project.
The options most Django developers consider
When you search for how to add social login to Django, you will find a handful of libraries that come up repeatedly.
django-allauth
django-allauth is one of the most well-known authentication packages in the Django ecosystem. It supports dozens of providers, handles email verification, and covers a wide range of authentication scenarios.
It is a great choice for traditional Django projects - the kind where Django renders the HTML pages itself and handles the full request/response cycle.
The challenge comes when you are building an API. django-allauth was designed around Django’s template system. Using it with a REST API and JWT tokens requires installing additional adapters like dj-rest-auth, configuring them to work together, and working through a setup process that can take a day or more. The documentation across these packages often refers to each other, so getting everything aligned takes effort.
If you are building a frontend in React, Next.js, Vue, or a mobile app - and your Django project is purely an API - django-allauth is more than you need.
python-social-auth (social-auth-app-django)
python-social-auth is another well-established library. It supports a very long list of providers and has been around for years.
It is powerful, but it is also built for projects that can afford to spend time on configuration. Setting it up involves adding custom pipeline steps, registering backends, understanding how the pipeline processes social login data, and in many cases writing extra code to wire things up the way you need.
For developers who want to understand every piece of what is happening, this level of control is valuable. For developers who want social login working this week without becoming OAuth experts, the learning curve is steep.
Building it yourself
Some developers skip the libraries entirely and write their own OAuth flow. This is a valid choice for teams with specific requirements, but it means handling:
- Validating tokens with Google or GitHub
- Protecting against CSRF attacks during the redirect flow
- Matching incoming social accounts to existing users
- Writing the endpoints your frontend will call
- Adding rate limiting to prevent abuse
- Testing every edge case
All of that is time that is not going into your actual product.
What makes django-social-auth-rest different
django-social-auth-rest was built specifically for one scenario: a Django REST API that needs social login and JWT tokens.
It is not trying to cover every possible use case. It does not come with a built-in template system or support for 30 providers. What it does instead is make the most common social login scenario - Google and GitHub, returning JWT tokens - as simple as it can possibly be.
Here is what that looks like in practice.
No middleware to register
Most authentication libraries ask you to add middleware to settings.py. django-social-auth-rest does not. You add the app to INSTALLED_APPS, add your provider credentials, include the URLs, and run migrations. That is the entire setup.
No custom backends
Some libraries require you to create or subclass authentication backends and register them. With django-social-auth-rest, there is nothing to subclass. The views, serializers, and logic are all handled inside the package.
No adapter layers
To use django-allauth with a REST API and JWT, you typically install dj-rest-auth on top of it to get REST endpoints, then configure them to work together. With django-social-auth-rest, the REST endpoints are already there. Install one package, and you are done.
JWT tokens out of the box
After a successful login - whether it is a new user or a returning one - the package returns a JWT access token and a refresh token. Your frontend can use them immediately. There is no extra configuration to get JWT tokens working; it is just what the package returns.
Same response shape for every provider
Whether a user logs in with Google or GitHub, the response looks exactly the same:
{ "access": "<jwt-access-token>", "refresh": "<jwt-refresh-token>" }
Your frontend does not need to handle different response formats depending on which button the user clicked.
CSRF protection built in
The GitHub login flow uses a signed, time-limited state token to prevent CSRF attacks. You do not need to implement this yourself or remember to add it - it is part of how the package works.
Rate limiting included
Every endpoint is protected against brute-force attempts out of the box. You can adjust the limit in your settings, but you do not need to add it yourself.
Signals for your own logic
When something happens - a new user registers, someone logs in, an account gets linked or unlinked - the package fires a Django signal. You can hook into these signals to send a welcome email, log the event, or trigger anything else your app needs. One decorator, and it is done.
A side-by-side comparison
| django-social-auth-rest | django-allauth | python-social-auth | |
|---|---|---|---|
| Built for REST APIs | Yes | Needs extra packages | Needs extra configuration |
| JWT tokens included | Yes | Needs dj-rest-auth | Manual setup |
| Middleware required | No | Yes | Yes |
| Custom backends required | No | No | Yes |
| Rate limiting included | Yes | No | No |
| CSRF protection included | Yes | Yes | Yes |
| Setup time (API project) | Under 10 minutes | Several hours | Several hours |
| Best for | API-first Django projects | Full-stack Django projects | Projects needing many providers |
When to choose something else
django-social-auth-rest is the right tool for API-first projects. There are situations where a different library makes more sense:
- You need many providers - If your project needs Facebook, Twitter, LinkedIn, Apple, and more,
python-social-authordjango-allauthcover a much wider range of providers. - You are building a traditional Django app - If Django is rendering your HTML pages,
django-allauthis a better fit because it integrates with Django’s template system. - You need advanced pipeline control - If your social login flow requires custom data processing at each step,
python-social-auth’s pipeline system gives you fine-grained control.
For those cases, those libraries are excellent choices.
But if you are building a REST API with a separate frontend, want Google and GitHub login, and want JWT tokens without a week of configuration - django-social-auth-rest gets you there in an afternoon.
What the setup actually looks like
Install:
pip install django-social-auth-rest
Settings:
INSTALLED_APPS = [
"rest_framework",
"django_social_auth_rest",
]
GOOGLE_CLIENT_ID = "your-google-client-id"
GITHUB_CLIENT_ID = "your-github-client-id"
GITHUB_CLIENT_SECRET = "your-github-client-secret"
SOCIAL_AUTH_STATE_SALT = "a-long-random-secret-value"
URLs:
urlpatterns = [
path("api/social-auth/", include("django_social_auth_rest.urls")),
path("api/social-auth/", include("django_social_auth_rest.urls.google")),
path("api/social-auth/", include("django_social_auth_rest.urls.github")),
]
Migrations:
python manage.py migrate
That is the complete setup. No middleware. No backends. No adapters. Your frontend can start calling /api/social-auth/google/login/ and /api/social-auth/github/login/ and receive JWT tokens back.
Final thought
The best library for a job is the one that matches what you are actually building. For API-first Django projects that need Google and GitHub login with JWT tokens, django-social-auth-rest removes almost all of the setup work so you can ship the feature and move on.
If you are starting a new project or adding social login to an existing Django REST API, give it a try.