Skip to main content

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

pargo_auth-0.1.4.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

pargo_auth-0.1.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pargo_auth-0.1.4.tar.gz.

File metadata

  • Download URL: pargo_auth-0.1.4.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

Hashes for pargo_auth-0.1.4.tar.gz
Algorithm Hash digest
SHA256 728f228fd362f649b329c7a1ec3e8c7e0ff83cf038aa0326f34c6417857794ae
MD5 25eb5e8498417a5e8896d7e33e0e2ab0
BLAKE2b-256 1614cdf3a2423d76031441199aa41bfb57e23912e67d6d60befbc3c2f45ae6e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pargo_auth-0.1.4.tar.gz:

Publisher: publish.yml on pargoorg/pargo-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pargo_auth-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pargo_auth-0.1.4-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

Hashes for pargo_auth-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 67db119456f1cc0fc7e218c2eb62bdf69b70a9526a04c0311afe4ddd125c740b
MD5 67a512ddaf4f72418dcb39eb15f6827b
BLAKE2b-256 0e9ea6e22d4634842ac3b2a3a40f2da9f5322fe4b6e80227196c6aaf04f8b769

See more details on using hashes here.

Provenance

The following attestation bundles were made for pargo_auth-0.1.4-py3-none-any.whl:

Publisher: publish.yml on pargoorg/pargo-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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