# 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
```bash
pip install drf-oauth2-tools
```
### Basic Setup
1. Add to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = [
# ... other apps
'rest_framework',
'drf_oauth2',
]
```
2. Configure OAuth providers in `settings.py`:
```python
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',
},
}
```
3. Add URLs to your `urls.py`:
```python
from django.urls import path, include
urlpatterns = [
path('api/auth/', include('drf_oauth2.urls')),
]
```
4. Run migrations:
```bash
python manage.py migrate
```
## ๐ฏ Usage
### API Endpoints
```bash # List available providers
GET /api/auth/oauth/login/google/ # Initiate Google OAuth
GET /api/auth/oauth/callback/google/ # Handle OAuth callback
```
### Frontend Integration
```javascript
// 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
```python
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
```python
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](LICENSE) file for details.
## ๐ Acknowledgments
- Django REST Framework team
- OAuth provider documentation
- Contributors and users
---
Made with โค๏ธ by [AstralMortem](https://github.com/AstralMortem)
Raw data
{
"_id": null,
"home_page": null,
"name": "drf-oauth2-tools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "django, django-rest-framework, oauth, social-login, authentication, google-oauth, facebook-oauth, github-oauth, jwt, social-auth",
"author": "Vladyslav Chaliuk",
"author_email": "chaliukvladyslav@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d7/83/d9aed2aa29966c05e7da65d9df34dca826bc546351bd8ae73cd3c25b3db0/drf_oauth2_tools-1.0.0.tar.gz",
"platform": null,
"description": "# README.md\n\n# DRF Social OAuth\n\n\nA highly extensible Django REST Framework library for OAuth social login with customizable providers and handlers.\n\n## \u2728 Features\n\n- \ud83d\udd10 **Multiple OAuth Providers**: Google, Facebook, GitHub, Twitter out of the box\n- \ud83c\udf9b\ufe0f **Highly Customizable**: Custom providers, handlers, and response formats \n- \ud83c\udfd7\ufe0f **DRF Native**: Built with ViewSets, Serializers, and proper REST patterns\n- \ud83d\udd11 **Multiple Auth Types**: JWT, Sessions, DRF Tokens supported\n- \ud83d\udee1\ufe0f **Security First**: CSRF protection, proper error handling, secure defaults\n- \ud83d\udcca **Admin Integration**: Django admin interface for social accounts\n- \ud83e\uddea **Well Tested**: Comprehensive test suite with high coverage\n- \ud83d\udcda **Great Documentation**: Detailed docs with examples\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\npip install drf-oauth2-tools\n```\n\n### Basic Setup\n\n1. Add to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n # ... other apps\n 'rest_framework',\n 'drf_oauth2',\n]\n```\n\n2. Configure OAuth providers in `settings.py`:\n\n```python\nOAUTH_PROVIDERS = {\n 'GOOGLE': {\n 'CLIENT_ID': 'your-google-client-id',\n 'CLIENT_SECRET': 'your-google-client-secret',\n },\n 'GITHUB': {\n 'CLIENT_ID': 'your-github-client-id',\n 'CLIENT_SECRET': 'your-github-client-secret',\n },\n}\n```\n\n3. Add URLs to your `urls.py`:\n\n```python\nfrom django.urls import path, include\n\nurlpatterns = [\n path('api/auth/', include('drf_oauth2.urls')),\n]\n```\n\n4. Run migrations:\n\n```bash\npython manage.py migrate\n```\n\n## \ud83c\udfaf Usage\n\n### API Endpoints\n\n```bash # List available providers\nGET /api/auth/oauth/login/google/ # Initiate Google OAuth\nGET /api/auth/oauth/callback/google/ # Handle OAuth callback\n```\n\n### Frontend Integration\n\n```javascript\n// Get authorization URL\nconst response = await fetch('/api/auth/oauth/login/google/');\nconst data = await response.json();\n\n// Redirect user to OAuth provider\nwindow.location.href = data.authorization_url;\n\n// After callback, you'll receive JWT tokens\n```\n\n\n## \ud83d\udd27 Advanced Configuration\n\n### Custom Callback Handler\n\n```python\nfrom drf_oauth2.handlers import BaseCallbackHandler\n\nclass CustomHandler(BaseCallbackHandler):\n def handle_callback(self, user_info, tokens, provider, request=None):\n user = self.get_or_create_user(user_info, provider)\n return {\n 'success': True,\n 'user_id': user.id,\n 'custom_data': 'your custom response'\n }\n\n# Configure in settings\nOAUTH_PROVIDERS = {\n 'GOOGLE': {\n 'CLIENT_ID': 'your-client-id',\n 'CLIENT_SECRET': 'your-client-secret', \n },\n \"CALLBACK_HANDLER_CLASS\": 'myapp.handlers.CustomHandler',\n}\n```\n\n### Custom OAuth Provider\n\n```python\nfrom drf_oauth2.providers import BaseOAuthProvider, register_provider\n\nclass LinkedInProvider(BaseOAuthProvider):\n PROVIDER = \"linkedin\"\n AUTHORIZATION_URL = \"https://www.linkedin.com/oauth/v2/authorization\"\n \n # ... implement other required methods\n\n# Configure in settings\nOAUTH_PROVIDERS = {\n 'LINKEDIN': {\n 'CLIENT_ID': 'your-client-id',\n 'CLIENT_SECRET': 'your-client-secret',\n \"PROVIDER_CLASS\": \"myapp.providers.linkedin.LinkedInProvider'\n },\n}\n\n```\n\n## \ud83d\udccb Supported Providers\n\n- **Google** - `google`\n- **Facebook** - `facebook` \n- **GitHub** - `github`\n- **Twitter** - `twitter`\n- **Custom providers** - Easy to add\n\n## \ud83d\udd10 Supported Authentication Types\n\n- **JWT Tokens** (via `djangorestframework-simplejwt`) (DEFAULT)\n- **Django Sessions** \n- **DRF Tokens**\n- **Custom handlers**\n\n\n## \ud83d\udcdd License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83d\ude4f Acknowledgments\n\n- Django REST Framework team\n- OAuth provider documentation\n- Contributors and users\n\n---\n\n\nMade with \u2764\ufe0f by [AstralMortem](https://github.com/AstralMortem)\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Comprehensive Django REST Framework library for OAuth social login",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/AstralMortem/drf-oauth2-tools",
"Repository": "https://github.com/AstralMortem/drf-oauth2-tools.git"
},
"split_keywords": [
"django",
" django-rest-framework",
" oauth",
" social-login",
" authentication",
" google-oauth",
" facebook-oauth",
" github-oauth",
" jwt",
" social-auth"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f2bb4b0c0b0db0cba7b4913777b90aca13c18098f21207a4a0aac1dc5a939f7f",
"md5": "ed1a248d7b6f2f9a6290e674a47800f1",
"sha256": "920e9a03da3b821a4ec0e3729f97879ce2c44aa5b0a18ac618536f689cd72855"
},
"downloads": -1,
"filename": "drf_oauth2_tools-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed1a248d7b6f2f9a6290e674a47800f1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 14890,
"upload_time": "2025-07-31T12:42:46",
"upload_time_iso_8601": "2025-07-31T12:42:46.290944Z",
"url": "https://files.pythonhosted.org/packages/f2/bb/4b0c0b0db0cba7b4913777b90aca13c18098f21207a4a0aac1dc5a939f7f/drf_oauth2_tools-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d783d9aed2aa29966c05e7da65d9df34dca826bc546351bd8ae73cd3c25b3db0",
"md5": "49fce6edb2eed7955e094203593e1f97",
"sha256": "448d440a068b66e9c32dd41aa1cabd9e665e66667782d6af181c7c39d64d41b5"
},
"downloads": -1,
"filename": "drf_oauth2_tools-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "49fce6edb2eed7955e094203593e1f97",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 10955,
"upload_time": "2025-07-31T12:42:48",
"upload_time_iso_8601": "2025-07-31T12:42:48.666853Z",
"url": "https://files.pythonhosted.org/packages/d7/83/d9aed2aa29966c05e7da65d9df34dca826bc546351bd8ae73cd3c25b3db0/drf_oauth2_tools-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-31 12:42:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AstralMortem",
"github_project": "drf-oauth2-tools",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "drf-oauth2-tools"
}