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 1.5 — depends on csrd-models and csrd-context only.

Installation

pip install "csrd-auth @ git+https://github.com/your-org/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 via csrd.versioning, find_token is injected automatically:

# Via versioning (token_finder = find_token by default)
from csrd.versioning.auth import create_jwt_bearer

auth_dep = create_jwt_bearer(key="your-secret")

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 1.5  csrd.auth · csrd.logging
Tier 2    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.1.44.tar.gz (12.9 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.1.44-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: csrd_auth-0.1.44.tar.gz
  • Upload date:
  • Size: 12.9 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.1.44.tar.gz
Algorithm Hash digest
SHA256 9a062084f40964fb93e792e00cc9f5fdb5ee6b9a21ee207f8619f52d74c48485
MD5 9e0c27ad652680940671b7df86c7969a
BLAKE2b-256 22c13ffbb1b3e25efa31a171f496e2f7e3eb498310cde75d564eba72e7907d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_auth-0.1.44.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.1.44-py3-none-any.whl.

File metadata

  • Download URL: csrd_auth-0.1.44-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.1.44-py3-none-any.whl
Algorithm Hash digest
SHA256 cd0e61528e192c5dd5c0a209bba7bcb6e0f971e02338b9f62762dda9ed2dbbe1
MD5 439d87de157266bc418ac662ba0e69b6
BLAKE2b-256 b31750d96588f1d499e409d8611049f580c01564b4be3e3986732deaa4dd9ce8

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_auth-0.1.44-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