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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pargo_auth-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 c1dd63086e15d52934778e2996882e60bd3cd4b0d5e415338bc74b02d413de6d
MD5 aba285ae97ee278bf7df0f8b0424a958
BLAKE2b-256 e3414e26e249a1b997f7edc7c4af3e25f0451f2e995328c479b0acc254084e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pargo_auth-0.1.5.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.5-py3-none-any.whl.

File metadata

  • Download URL: pargo_auth-0.1.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 85de26beb35dfc5392494b63f87448e2a7ba365a340dd2153fc3b19e26c01628
MD5 87abd7d223c4236581a36fee90094612
BLAKE2b-256 be2da264adc98eba6ad27ebb9a79c33db4fb4fb42be99bd14ac916ab2f4bbb17

See more details on using hashes here.

Provenance

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