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.2.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.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

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

Hashes for pargo_auth-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9c5fa2c1ecfebe758e34adbc3d39bd084c11688ba3c92a30294f29a7f2b661f5
MD5 b2c1fd31eac97e41aa868c5fb6321f2b
BLAKE2b-256 a3d47bad5c55ca2fffa798d8f223c755106727d020eb5118763168da995d36cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pargo_auth-0.1.2.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.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

Hashes for pargo_auth-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 404ba9309eb29ba0a799f4ce8e2428b752d06cfd80f2a328e96c5b0aba92a744
MD5 43939b74dd1185c7c9bdf817ff3dae99
BLAKE2b-256 a08b15d6a72e02cdd237cdab7aebba71f9535aa7dc1edf59b89962768689d9c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pargo_auth-0.1.2-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