Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trishul_oauth_client-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trishul_oauth_client-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file trishul_oauth_client-0.1.1.tar.gz.

File metadata

  • Download URL: trishul_oauth_client-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for trishul_oauth_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b26efc91ea45fa58b0c50fc7fb3a1204877b737702cbbc64882db38bb03f3edc
MD5 0995ecc6f60ab6026d9807e52dbd84dc
BLAKE2b-256 12090323428a99c2fc89bf8ef80c31a1249864e8a392df2233ce53e04fcd5f8d

See more details on using hashes here.

File details

Details for the file trishul_oauth_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for trishul_oauth_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31e667715c0bb702f49043dc1b1e676619c3c2b7c731c23e46b76a9f5f7839d1
MD5 f47f978a35ea1f506a590dbb98ea159f
BLAKE2b-256 7544b14843644d8b203f3b229afa2cd7f8c1c81a962fd8994b812569e92ffbeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page