Official Django SDK for Syauth Authentication
Project description
Django SDK for Syauth
Official Django integration for Syauth - a modern authentication platform.
Features
- 🔐 OAuth 2.0 Authorization Code Flow with PKCE
- 🚀 Drop-in views for Login, Callback, and Logout
- 🔒 Secure token management
- 🛡️ Protected routes with decorators
- 🎨 Easy integration with Django's authentication system
Installation
pip install django-syauth
Quick Start
1. Add to INSTALLED_APPS
INSTALLED_APPS = [
...
'django_syauth',
]
2. Configure Authentication Backends
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_syauth.backend.SyauthBackend',
]
3. Add Syauth Settings
SYAUTH = {
'API_URL': 'https://api.syauth.com/e/v1',
'CLIENT_ID': 'your-client-id',
'REDIRECT_URI': 'http://localhost:8000/auth/callback',
'API_KEY': 'your-api-key',
'SCOPES': ['openid', 'profile', 'email'],
# 'CLIENT_SECRET': 'your-secret', # Only for server-to-server clients
}
4. Include URLs
from django.urls import path, include
urlpatterns = [
path('auth/', include('django_syauth.urls')),
# ... your other urls
]
Usage
Protecting Views
Use the @syauth_login_required decorator to protect views:
from django_syauth.decorators import syauth_login_required
@syauth_login_required
def dashboard(request):
return render(request, 'dashboard.html')
Template URLs
In your templates, use the named URLs:
<a href="{% url 'django_syauth:login' %}">Sign In</a>
<a href="{% url 'django_syauth:logout' %}">Sign Out</a>
Accessing User Info
After login, user information is available via request.user:
def profile(request):
email = request.user.email
first_name = request.user.first_name
last_name = request.user.last_name
# ...
Configuration Options
| Setting | Required | Description |
|---|---|---|
API_URL |
✅ | Syauth API URL (e.g., https://api.syauth.com/e/v1) |
CLIENT_ID |
✅ | Your OAuth Client ID |
REDIRECT_URI |
✅ | Callback URL (must match Syauth Dashboard) |
API_KEY |
✅ | Your API Key from Syauth Dashboard |
SCOPES |
❌ | OAuth scopes (default: ['openid', 'profile', 'email']) |
CLIENT_SECRET |
❌ | Only for server-to-server (confidential) clients |
Example Application
Check out the example application for a complete working demo.
Running the Example
cd examples/django-app-with-sdk
# Copy and configure environment
cp .env.example .env
# Edit .env with your Syauth credentials
# Install dependencies
pip install django requests pyjwt[crypto]
# Run migrations
python manage.py migrate
# Start the server
python manage.py runserver
Using with ngrok
For development with external OAuth providers, you may need to use ngrok. See the ngrok guide for setup instructions.
Documentation
Full documentation is available at developers.nexorix.com/syauth.
License
MIT License - see LICENSE for details.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_syauth-0.1.0.tar.gz.
File metadata
- Download URL: django_syauth-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
522b825357d31782d487842b73ad37c8c5b609e8e4a6b8006759b6f20b5e05fd
|
|
| MD5 |
17ca3df84ecdd0d89dbd18072d6ee3c7
|
|
| BLAKE2b-256 |
aa123e3073a1151f9697109adf1bde90cb6a791dca4160584c5873346664993b
|
File details
Details for the file django_syauth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_syauth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ae0d49bade7559efc1a19c5ea03f8fca6aac1b149ad328a0130fdddd3ee443
|
|
| MD5 |
f512bff7ec05c8ed0c635de0b69531c0
|
|
| BLAKE2b-256 |
b4def13b3da27e951839a36222894c5b9fd256e66f9a5144b0aad597ec921b10
|