Shared, hardened JWT verification core for OIDC/JWKS issuers
Project description
oidc-jwt-verifier
oidc-jwt-verifier is a small, framework-agnostic JWT verification core for OIDC/JWKS issuers.
It is designed to be shared by higher-level adapters (Dash, Bottle, Lambda, FastAPI) while keeping security decisions centralized and consistent.
Install
pip install oidc-jwt-verifier
For development:
uv pip install -e ".[dev]"
Quickstart
from oidc_jwt_verifier import AuthConfig, JWTVerifier
config = AuthConfig(
issuer="https://example-issuer/",
audience="https://example-api",
jwks_url="https://example-issuer/.well-known/jwks.json",
allowed_algs=("RS256",),
required_scopes=("read:users",),
)
verifier = JWTVerifier(config)
claims = verifier.verify_access_token(token)
Secure-by-default behavior
The verifier:
- Verifies signature,
iss,aud,exp, andnbf(when present). - Uses an explicit algorithm allowlist and rejects
alg=none. - Fails closed on malformed tokens, JWKS fetch errors, timeouts, missing keys, and missing
kid. - Never derives a JWKS URL from token headers, and rejects tokens that include
jku,x5u, orcrit. - Supports Auth0-style multi-audience tokens (
audas an array) and enforces required scopes and permissions.
Auth0 guidance for API token validation calls out validating the JWT and then checking aud and
scopes in the scope claim. See the Auth0 docs for details.
Error handling
The public exception type is AuthError.
AuthError carries:
code: stable, machine-readable reasonstatus_code:401(authentication) or403(authorization)www_authenticate_header(): an RFC 6750 compatibleWWW-Authenticatevalue for Bearer auth
from oidc_jwt_verifier import AuthError
try:
claims = verifier.verify_access_token(token)
except AuthError as err:
status = err.status_code
www_authenticate = err.www_authenticate_header()
Why this library
JWT verification for APIs is easy to get mostly right while still missing important security and interoperability details. This library is a small, framework-agnostic core that centralizes conservative verification policy (claims, algorithms, header handling) and authorization checks (scopes/permissions) so you can reuse it across projects.
For comparisons against common alternatives (PyJWT directly, discovery-driven verifiers, framework
integrations), see docs/alternatives.md.
Contributing
We use Conventional Commits to automate releases via release-please.
Commit prefixes:
feat:- New feature (bumps PATCH pre-v1.0)feat!:- Breaking change (bumps MINOR pre-v1.0)fix:- Bug fix (bumps PATCH)docs:- Documentation onlychore:- Maintenance tasksrefactor:- Code refactoringtest:- Test changesperf:- Performance improvements
PRs without conventional commit prefixes will not trigger releases.
References
- Auth0: Validate Access Tokens:
https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens - Auth0: Validate JSON Web Tokens:
https://auth0.com/docs/secure/tokens/json-web-tokens/validate-json-web-tokens - RFC 8725: JSON Web Token Best Current Practices:
https://datatracker.ietf.org/doc/html/rfc8725 - RFC 9700: Best Current Practice for OAuth 2.0 Security:
https://www.rfc-editor.org/info/rfc9700 - PyJWT docs and examples:
https://github.com/jpadilla/pyjwt/blob/master/docs/usage.rst
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 oidc_jwt_verifier-0.1.3.tar.gz.
File metadata
- Download URL: oidc_jwt_verifier-0.1.3.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa1c945078881dbe025e99878566b33e0a253284f854e9023e14841558e8e228
|
|
| MD5 |
a5d54d1bc1e9b80712d7da6f73d29112
|
|
| BLAKE2b-256 |
d92bec9daf0e9d08348a99766114182f8938d2c3a3b625b5896388c516810f9a
|
Provenance
The following attestation bundles were made for oidc_jwt_verifier-0.1.3.tar.gz:
Publisher:
release.yml on BjornMelin/oidc-jwt-verifier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oidc_jwt_verifier-0.1.3.tar.gz -
Subject digest:
fa1c945078881dbe025e99878566b33e0a253284f854e9023e14841558e8e228 - Sigstore transparency entry: 771841913
- Sigstore integration time:
-
Permalink:
BjornMelin/oidc-jwt-verifier@fe2be2357ba792063232b7d6959de085395c84a5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BjornMelin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fe2be2357ba792063232b7d6959de085395c84a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file oidc_jwt_verifier-0.1.3-py3-none-any.whl.
File metadata
- Download URL: oidc_jwt_verifier-0.1.3-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4748b821ebd2d6a06b9b9e9efb77dd0277cfd81adcb0c10d3590367965fc668
|
|
| MD5 |
56f5fbed100cdee7f20d385a3f7b1b40
|
|
| BLAKE2b-256 |
21dd4d56805382a48dd1aa60b715e8d6eac68d0800e5ef9e6168fc4146d584c8
|
Provenance
The following attestation bundles were made for oidc_jwt_verifier-0.1.3-py3-none-any.whl:
Publisher:
release.yml on BjornMelin/oidc-jwt-verifier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oidc_jwt_verifier-0.1.3-py3-none-any.whl -
Subject digest:
e4748b821ebd2d6a06b9b9e9efb77dd0277cfd81adcb0c10d3590367965fc668 - Sigstore transparency entry: 771841915
- Sigstore integration time:
-
Permalink:
BjornMelin/oidc-jwt-verifier@fe2be2357ba792063232b7d6959de085395c84a5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BjornMelin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fe2be2357ba792063232b7d6959de085395c84a5 -
Trigger Event:
push
-
Statement type: