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/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) -> UserClaimsKeyProvider—(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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csrd_auth-0.3.13.tar.gz.
File metadata
- Download URL: csrd_auth-0.3.13.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e0641c81ae83e1a2efed7c67e65db82fb65b27f41d825c03cb2154afd009be1
|
|
| MD5 |
39a54c8c432cbcc521129afd03b8900d
|
|
| BLAKE2b-256 |
cf23c2671a8d6f27037b424cbeeb62a7c1271e353a44c111dbbf86e3bb8009a5
|
Provenance
The following attestation bundles were made for csrd_auth-0.3.13.tar.gz:
Publisher:
release.yml on csrd-api/fastapi-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csrd_auth-0.3.13.tar.gz -
Subject digest:
9e0641c81ae83e1a2efed7c67e65db82fb65b27f41d825c03cb2154afd009be1 - Sigstore transparency entry: 1421880147
- Sigstore integration time:
-
Permalink:
csrd-api/fastapi-common@851fd3a77c1ed803b5dfb994733c8699a6aeefd1 -
Branch / Tag:
refs/tags/v0.3.13 - Owner: https://github.com/csrd-api
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@851fd3a77c1ed803b5dfb994733c8699a6aeefd1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file csrd_auth-0.3.13-py3-none-any.whl.
File metadata
- Download URL: csrd_auth-0.3.13-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bab10bd0beb40cc28090d0621a93e653043d48bc7426543501d6512a902f83e
|
|
| MD5 |
0736f4aa5b6f92d84e244afa04b95b8a
|
|
| BLAKE2b-256 |
528e4e90cabda6e3ea3f24b2e855872c028f8a8dccf4407928d400119465cd2f
|
Provenance
The following attestation bundles were made for csrd_auth-0.3.13-py3-none-any.whl:
Publisher:
release.yml on csrd-api/fastapi-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csrd_auth-0.3.13-py3-none-any.whl -
Subject digest:
9bab10bd0beb40cc28090d0621a93e653043d48bc7426543501d6512a902f83e - Sigstore transparency entry: 1421880413
- Sigstore integration time:
-
Permalink:
csrd-api/fastapi-common@851fd3a77c1ed803b5dfb994733c8699a6aeefd1 -
Branch / Tag:
refs/tags/v0.3.13 - Owner: https://github.com/csrd-api
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@851fd3a77c1ed803b5dfb994733c8699a6aeefd1 -
Trigger Event:
workflow_dispatch
-
Statement type: