Shared authentication middleware for PARGO backend services
Project description
pargo-auth
Shared authentication middleware for PARGO backend services. Verifies Supabase JWTs and provides FastAPI dependencies.
Installation
pip install pargo-auth
Quick Start
from fastapi import FastAPI, Depends
from pargo_auth import get_current_user, AuthenticatedUser
app = FastAPI()
@app.get("/me")
async def get_me(user: AuthenticatedUser = Depends(get_current_user)):
return {
"id": user.sub,
"email": user.email,
}
Configuration
Set these environment variables:
SUPABASE_URL=https://your-project.supabase.co
ENV=local # Skip auth verification in local dev
Usage Patterns
Basic: Protect individual endpoints
from pargo_auth import get_current_user, AuthenticatedUser
@app.get("/protected")
async def protected(user: AuthenticatedUser = Depends(get_current_user)):
return {"user_id": user.sub}
Protect entire router
from fastapi import APIRouter, Depends
from pargo_auth import require_auth
router = APIRouter(dependencies=[require_auth()])
@router.get("/data")
async def get_data(): # Auth already required by router
return {"data": "secret"}
Optional auth (different behavior for logged-in vs anonymous)
from pargo_auth import SupabaseAuth, AuthenticatedUser
auth = SupabaseAuth()
@app.get("/content")
async def get_content(user: AuthenticatedUser | None = Depends(auth.get_user_optional)):
if user:
return {"content": "personalized", "user": user.sub}
return {"content": "generic"}
Custom instance (non-default config)
from pargo_auth import SupabaseAuth
auth = SupabaseAuth(
supabase_url="https://custom.supabase.co",
skip_verification_in_dev=False, # Always verify, even locally
)
@app.get("/strict")
async def strict_endpoint(user = Depends(auth.get_user)):
return {"user": user.sub}
AuthenticatedUser
The AuthenticatedUser object contains:
| Field | Type | Description |
|---|---|---|
sub |
str |
Supabase user ID (stable, use as canonical identity) |
email |
str | None |
User's email (if available) |
email_verified |
bool |
Whether email is verified |
raw_claims |
dict | None |
Full JWT payload for custom claims |
Legacy Support
For backwards compatibility, the middleware also checks for x-user-id header if no Bearer token is present. This allows gradual migration from the old auth system.
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
License
MIT
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
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 pargo_auth-0.1.2.tar.gz.
File metadata
- Download URL: pargo_auth-0.1.2.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c5fa2c1ecfebe758e34adbc3d39bd084c11688ba3c92a30294f29a7f2b661f5
|
|
| MD5 |
b2c1fd31eac97e41aa868c5fb6321f2b
|
|
| BLAKE2b-256 |
a3d47bad5c55ca2fffa798d8f223c755106727d020eb5118763168da995d36cb
|
Provenance
The following attestation bundles were made for pargo_auth-0.1.2.tar.gz:
Publisher:
publish.yml on pargoorg/pargo-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pargo_auth-0.1.2.tar.gz -
Subject digest:
9c5fa2c1ecfebe758e34adbc3d39bd084c11688ba3c92a30294f29a7f2b661f5 - Sigstore transparency entry: 902157165
- Sigstore integration time:
-
Permalink:
pargoorg/pargo-auth@1c0750f0d68036bc8693530b7c9958886d3a29c5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pargoorg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c0750f0d68036bc8693530b7c9958886d3a29c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pargo_auth-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pargo_auth-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
404ba9309eb29ba0a799f4ce8e2428b752d06cfd80f2a328e96c5b0aba92a744
|
|
| MD5 |
43939b74dd1185c7c9bdf817ff3dae99
|
|
| BLAKE2b-256 |
a08b15d6a72e02cdd237cdab7aebba71f9535aa7dc1edf59b89962768689d9c6
|
Provenance
The following attestation bundles were made for pargo_auth-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on pargoorg/pargo-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pargo_auth-0.1.2-py3-none-any.whl -
Subject digest:
404ba9309eb29ba0a799f4ce8e2428b752d06cfd80f2a328e96c5b0aba92a744 - Sigstore transparency entry: 902157309
- Sigstore integration time:
-
Permalink:
pargoorg/pargo-auth@1c0750f0d68036bc8693530b7c9958886d3a29c5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pargoorg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c0750f0d68036bc8693530b7c9958886d3a29c5 -
Trigger Event:
push
-
Statement type: