Skip to main content

Pluggable JWT authentication — authenticators, key providers, and FastAPI dependency factories

Project description

csrd-auth

Pluggable JWT authentication for FastAPI — authenticators, key providers, and dependency factories.

Tier 2 (bridge) — depends on csrd-models and csrd-context only.

Installation

pip install "csrd-auth @ git+https://github.com/csrd-api/fastapi-common.git#subdirectory=packages/auth"

Usage

from csrd.auth import (
    JWTAuthenticator,
    StaticKeyProvider,
    create_bearer_dependency,
    create_jwt_bearer,
)

Quick start — JWT bearer dependency

# Standalone (provide your own token_finder)
from csrd.auth import create_jwt_bearer

auth_dep = create_jwt_bearer(
    key="your-secret",
    token_finder=lambda: extract_token_from_request(),
)

When used with csrd.versioning, wire in find_token explicitly:

from csrd.auth import create_jwt_bearer
from csrd.versioning import find_token

auth_dep = create_jwt_bearer(key="your-secret", token_finder=find_token)

Authenticators

Class Strategy
JWTAuthenticator Decode & verify JWT locally via PyJWT
StaticAuthenticator Accept a fixed token (dev/testing)
RemoteAuthenticator Validate via upstream HTTP endpoint
CallbackAuthenticator Delegate to any sync/async callable
ChainedAuthenticator Try multiple authenticators in order

Key Providers

Class Strategy
StaticKeyProvider Fixed string, bytes, or SecretStr
EnvKeyProvider Read from app.state or settings loader
JWKSKeyProvider Fetch from JWKS endpoint (cached with TTL)
MultiKeyProvider Route by kid header or try all
CallbackKeyProvider Delegate to any callable

Protocols

  • Authenticator(Request, str) -> UserClaims
  • KeyProvider(token_headers, app) -> key

Both are @runtime_checkable protocols.

Dependency Tier

Tier 1      csrd.models  csrd.lifespan  csrd.context
Tier 2      csrd.auth  csrd.logging  csrd.delegate  csrd.repository  csrd.service
Tier 3      csrd.versioning

csrd.auth depends only on csrd.models (for UserClaims) and csrd.context (for user_info_context). It has no dependency on csrd.versioning.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csrd_auth-0.3.91.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

csrd_auth-0.3.91-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file csrd_auth-0.3.91.tar.gz.

File metadata

  • Download URL: csrd_auth-0.3.91.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for csrd_auth-0.3.91.tar.gz
Algorithm Hash digest
SHA256 cf9a62d1a1c67396eb9f71800962212fc807fcb424412dd9ae9ef7acf21808ef
MD5 a3d5172741685059b1ba3bb466904179
BLAKE2b-256 e80da35077343d623646a74917bc5d659eeb2f9018c6253926b1ce5bcbcfd2ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_auth-0.3.91.tar.gz:

Publisher: release.yml on csrd-api/fastapi-common

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

File details

Details for the file csrd_auth-0.3.91-py3-none-any.whl.

File metadata

  • Download URL: csrd_auth-0.3.91-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for csrd_auth-0.3.91-py3-none-any.whl
Algorithm Hash digest
SHA256 9e60217f8de3cef9dc1c2cd7bf147d714481be25207571cd6dc1fea37bb9a96e
MD5 150871f5446963c7881edfc7a6861262
BLAKE2b-256 bed69ed606f96577bc9e156b8b6d5450e31597c0dab8f56c0eac21249604086b

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_auth-0.3.91-py3-none-any.whl:

Publisher: release.yml on csrd-api/fastapi-common

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