README.md
DRF Social OAuth
A highly extensible Django REST Framework library for OAuth social login with customizable providers and handlers.
✨ Features
- 🔐 Multiple OAuth Providers: Google, Facebook, GitHub, Twitter out of the box
- 🎛️ Highly Customizable: Custom providers, handlers, and response formats
- 🏗️ DRF Native: Built with ViewSets, Serializers, and proper REST patterns
- 🔑 Multiple Auth Types: JWT, Sessions, DRF Tokens supported
- 🛡️ Security First: CSRF protection, proper error handling, secure defaults
- 📊 Admin Integration: Django admin interface for social accounts
- 🧪 Well Tested: Comprehensive test suite with high coverage
- 📚 Great Documentation: Detailed docs with examples
🚀 Quick Start
Installation
pip install drf-oauth2-tools
Basic Setup
- Add to your
INSTALLED_APPS:
INSTALLED_APPS = [
# ... other apps
'rest_framework',
'drf_oauth2',
]
- Configure OAuth providers in
settings.py:
OAUTH_PROVIDERS = {
'GOOGLE': {
'CLIENT_ID': 'your-google-client-id',
'CLIENT_SECRET': 'your-google-client-secret',
},
'GITHUB': {
'CLIENT_ID': 'your-github-client-id',
'CLIENT_SECRET': 'your-github-client-secret',
},
}
- Add URLs to your
urls.py:
from django.urls import path, include
urlpatterns = [
path('api/auth/', include('drf_oauth2.urls')),
]
- Run migrations:
python manage.py migrate
🎯 Usage
API Endpoints
GET /api/auth/oauth/login/google/ # Initiate Google OAuth
GET /api/auth/oauth/callback/google/ # Handle OAuth callback
Frontend Integration
// Get authorization URL
const response = await fetch('/api/auth/oauth/login/google/');
const data = await response.json();
// Redirect user to OAuth provider
window.location.href = data.authorization_url;
// After callback, you'll receive JWT tokens
🔧 Advanced Configuration
Custom Callback Handler
from drf_oauth2.handlers import BaseCallbackHandler
class CustomHandler(BaseCallbackHandler):
def handle_callback(self, user_info, tokens, provider, request=None):
user = self.get_or_create_user(user_info, provider)
return {
'success': True,
'user_id': user.id,
'custom_data': 'your custom response'
}
# Configure in settings
OAUTH_PROVIDERS = {
'GOOGLE': {
'CLIENT_ID': 'your-client-id',
'CLIENT_SECRET': 'your-client-secret',
},
"CALLBACK_HANDLER_CLASS": 'myapp.handlers.CustomHandler',
}
Custom OAuth Provider
from drf_oauth2.providers import BaseOAuthProvider, register_provider
class LinkedInProvider(BaseOAuthProvider):
PROVIDER = "linkedin"
AUTHORIZATION_URL = "https://www.linkedin.com/oauth/v2/authorization"
# ... implement other required methods
# Configure in settings
OAUTH_PROVIDERS = {
'LINKEDIN': {
'CLIENT_ID': 'your-client-id',
'CLIENT_SECRET': 'your-client-secret',
"PROVIDER_CLASS": "myapp.providers.linkedin.LinkedInProvider'
},
}
📋 Supported Providers
- Google -
google - Facebook -
facebook - GitHub -
github - Twitter -
twitter - Custom providers - Easy to add
🔐 Supported Authentication Types
- JWT Tokens (via
djangorestframework-simplejwt) (DEFAULT) - Django Sessions
- DRF Tokens
- Custom handlers
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Django REST Framework team
- OAuth provider documentation
- Contributors and users
Made with ❤️ by AstralMortem
Release files for drf-oauth2-tools 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_oauth2_tools-1.0.2.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_oauth2_tools-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.8 kB
Release files / drf_oauth2_tools-1.0.2.tar.gz
| Download URL | drf_oauth2_tools-1.0.2.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a83c5c8790364d6778a25ec6ee1809bbeb0d1b7b6875a0ffbbb2123191fe4840
|
|
BLAKE2b-256 checksum How to use checksums |
bcaec1c735c46cb5d181098ccf1588d9b91f21bd3c67f91ce2258b32b22bbc18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.
Transparency logRelease files / drf_oauth2_tools-1.0.2-py3-none-any.whl
| Download URL | drf_oauth2_tools-1.0.2-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
866dd8efd8135b84149741b670f11a5942737f9b2726ffb37b40111968b108c2
|
|
BLAKE2b-256 checksum How to use checksums |
8ac3be95c2f3ebb71c8f5583f86fd0306b489a67c0e88183e9f7f60a6ac8e040
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.
Transparency log