Enterprise-grade OIDC/OAuth client library for Python (FastAPI, Flask, Django)
Project description
Trishul OAuth Client for Python
An enterprise-grade, highly secure OIDC/OAuth 2.0 client library for Python. Supports standard OIDC authorization code flow with secure PKCE validation, state validation, and plug-and-play integrations for FastAPI, Flask, and Django.
Features
- Sync & Async Core Engine: Fully support both sync and async frameworks out-of-the-box.
- Secure PKCE (S256): Auto-generated PKCE verification pairs for absolute security against code interception attacks.
- OIDC Discovery Configuration: Automatic parsing and local caching of the openid-configuration metadata.
- Cryptographic Signature Verification: Validates ID Token signatures locally using the server's JWKS endpoint.
- Automatic Silent Token Rotation: Seamless refresh-token based token rotation without user disruption.
- Out-of-the-Box Web Framework Integrations for:
- FastAPI / Starlette
- Flask
- Django
Installation
Install from PyPI (once published):
pip install trishul-oauth-client
Or install with framework-specific dependency packages:
# For FastAPI
pip install "trishul-oauth-client[fastapi]"
# For Flask
pip install "trishul-oauth-client[flask]"
# For Django
pip install "trishul-oauth-client[django]"
Quickstart
1. Initialize Client
from trishul_oauth import TrishulOAuth, MemoryStorage
client = TrishulOAuth({
"issuer": "https://identity.yourdomain.com",
"clientId": "your_client_id",
"clientSecret": "your_client_secret",
"redirectUri": "http://localhost:8000/callback",
"usePKCE": True,
})
Web Framework Integrations
1. FastAPI / Starlette
Fully async dependency injection provider:
from fastapi import FastAPI, Depends, HTTPException
from trishul_oauth import TrishulOAuth
from trishul_oauth.integrations.fastapi import TrishulSecurity
app = FastAPI()
client = TrishulOAuth({
"issuer": "https://identity.yourdomain.com",
"clientId": "your_client_id",
"redirectUri": "http://localhost:8000/callback",
})
# Initialize FastAPI Security provider
security = TrishulSecurity(client)
@app.get("/api/dashboard")
async def dashboard(user = Depends(security.require_auth(scopes=["profile"]))):
return {
"status": "success",
"message": f"Welcome back, {user.get('name')}!",
"profile": user
}
2. Flask
Clean view decorators and session injectors:
from flask import Flask, session, render_template
from trishul_oauth import TrishulOAuth
from trishul_oauth.integrations.flask import FlaskOAuth
app = Flask(__name__)
app.secret_key = "your_super_secret_session_key"
client = TrishulOAuth({
"issuer": "https://identity.yourdomain.com",
"clientId": "your_client_id",
"clientSecret": "your_client_secret",
"redirectUri": "http://localhost:5000/callback",
})
oauth = FlaskOAuth(client)
@app.route("/dashboard")
@oauth.require_auth(scopes=["profile"])
def dashboard():
# Retrieve user info from global Flask context
user = oauth.current_user
return f"Welcome back, {user['name']}!"
3. Django
Middleware and view decorators for robust authentication:
# settings.py
INSTALLED_APPS = [
...
'django.contrib.sessions',
]
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
'trishul_oauth.integrations.django.TrishulOAuthMiddleware',
]
from trishul_oauth import TrishulOAuth
TRISHUL_OAUTH_CLIENT = TrishulOAuth({
"issuer": "https://identity.yourdomain.com",
"clientId": "your_client_id",
"clientSecret": "your_client_secret",
})
# views.py
from django.http import JsonResponse
from trishul_oauth.integrations.django import require_auth
@require_auth(scopes=["profile"])
def dashboard_view(request):
user = request.trishul_user
return JsonResponse({
"status": "success",
"user": user
})
Running Package Tests
Verify everything runs cleanly using pytest:
pytest tests/
License
MIT License. See LICENSE for details.
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 trishul_oauth_client-0.1.3.tar.gz.
File metadata
- Download URL: trishul_oauth_client-0.1.3.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58a9e432d9cee5cd0a3a46ea468db9cd491c92fe0a0780683662a66e241432e2
|
|
| MD5 |
c6b1566f8d4704372db638e595b6a791
|
|
| BLAKE2b-256 |
5c4b239bc5f8c57244c277f5ddcedb28adb4944e841d8f7de35df3ef4f9841ac
|
File details
Details for the file trishul_oauth_client-0.1.3-py3-none-any.whl.
File metadata
- Download URL: trishul_oauth_client-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70b8bdc74f6fa35a17e850fb314d0f33cb77abb956e1e4c4a1b876758d5f43f9
|
|
| MD5 |
eee84a70a19e443edc44b02cd591e167
|
|
| BLAKE2b-256 |
332db305f74949e7397f69d75ad95d4bc8f1069606ab49313f63c184210b0e5a
|