Skip to main content

bdr-auth-library

Shared Supabase Auth library for FastAPI applications. Provides JWT verification via JWKS, tenant extraction, service-to-service tokens, token refresh coordination, rate limiting, and FastAPI dependencies.

Installation

pip install bdr-auth-library

Quick Start

from fastapi import FastAPI, Depends
from auth_library.dependencies import get_current_user
from auth_library.models import User
from auth_library.errors import AuthError, auth_error_handler

app = FastAPI()
app.add_exception_handler(AuthError, auth_error_handler)

@app.get("/protected")
async def protected(user: User = Depends(get_current_user)):
    return {"uid": user.uid, "tenant": user.effective_tenant_id}

Environment Variables

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_JWKS_URL=https://your-project.supabase.co/auth/v1/.well-known/jwks.json
APP_ENV=production
DISABLE_AUTH=false

Features

  • JWT Verification — RS256 via JWKS with automatic key rotation support
  • Issuer Registry — Algorithm-confusion prevention; determines expected algorithm from trusted config, not token headers
  • JWKS Caching — TTL-based caching (default 10min) with force-refresh on unknown kid
  • Tenant Extraction — Priority resolution: custom claim → app_metadata → uid fallback
  • Service Tokens — HS256 internal service-to-service tokens with dedicated signing secret
  • Token Refresh — Proactive refresh with async lock to prevent parallel refresh storms
  • Rate Limiting — Per-IP global limit, failed login throttling, per-account protection
  • Dual Verification — Accept both Supabase and legacy Firebase tokens during migration
  • FastAPI Integration — get_current_user dependency, standardized error responses
  • Secure Logging — Redacts tokens/secrets from all log output

API

Dependencies

from auth_library.dependencies import get_current_user

Returns an authenticated User model or raises HTTP 401 with a standardized error response.

User Model

from auth_library.models import User

# Fields: uid, email, email_verified, display_name, photo_url, role, tenant_id
# Computed: effective_tenant_id (tenant_id or uid fallback, never empty)

Service Tokens

from auth_library.service_client import ServiceTokenGenerator

generator = ServiceTokenGenerator(signing_secret="your-secret")
token = generator.generate(service_name="my-service", ttl=300)

Token Refresh

from auth_library.refresh import TokenRefreshCoordinator

coordinator = TokenRefreshCoordinator(settings)
access_token = await coordinator.get_valid_token()

Configuration

All settings are loaded via Pydantic BaseSettings from environment variables:

Variable Required Default Description
SUPABASE_URL Yes — Supabase project URL
SUPABASE_JWKS_URL Yes — JWKS endpoint for token verification
APP_ENV No development Environment (development/test/staging/production)
DISABLE_AUTH No false Bypass auth in dev/test only
DUAL_VERIFICATION_ENABLED No false Accept legacy Firebase tokens
SUPABASE_SERVICE_ROLE_KEY No — For ServiceRoleClient (bypasses RLS)
SERVICE_TOKEN_SECRET No — Signing secret for internal service tokens

License

MIT

Metadata

Release files for bdr-auth-library 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bdr-auth-library 0.2.0
File Size Uploaded Provenance
bdr_auth_library-0.2.0.tar.gz 75.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bdr-auth-library 0.2.0
File Interpreter ABI Platform
bdr_auth_library-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 103.1 kB

Release files / bdr_auth_library-0.2.0.tar.gz

Download URL bdr_auth_library-0.2.0.tar.gz
Size 75.7 kB
Tags Source
SHA-256 checksum
How to use checksums
246f11143f7ad1949c9f4cfd25bd30bac67f9bb44a74f096c93fb39b7677bd64
BLAKE2b-256 checksum
How to use checksums
8f4dcb5f29f5a27e3759ad5e32b824248ca4a4bbb95a9db2d9963cc5f218338f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / bdr_auth_library-0.2.0-py3-none-any.whl

Download URL bdr_auth_library-0.2.0-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58dcdb69d0f0d4599f2472b3950d53f2f10977ca5c140b25baeebb3d92fcd225
BLAKE2b-256 checksum
How to use checksums
4fb64303954d28a37bfee9da198719deda2ecf0169e0aabd25e78b6c00b7e860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for bdr-auth-library 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page