nat.authentication.jwt_utils#
Lightweight JWT extraction and decoding utilities for identity resolution (RFC 7519).
Functions#
|
Extract the raw Bearer token string from an HTTP header. |
|
Decode JWT claims without signature verification (RFC 7519 Section 7.2). |
Module Contents#
- extract_bearer_token(
- connection: starlette.requests.Request | fastapi.WebSocket,
- *,
- header: str = 'authorization',
Extract the raw Bearer token string from an HTTP header.
- Args:
connection: The incoming Starlette
RequestorWebSocket. header: Header name to read the Bearer token from (case-insensitive).- Returns:
The raw token string, or
Noneif no valid Bearer token is present.
- decode_jwt_claims_unverified(token: str) dict[str, Any]#
Decode JWT claims without signature verification (RFC 7519 Section 7.2).
Intended for identity extraction only — callers are responsible for authenticating/verifying tokens via JWKS, OAuth flows, or other auth middleware before trusting the claims.
- Args:
token: A raw JWT string (three dot-separated parts per RFC 7519 Section 3).
- Returns:
The decoded claims dictionary.
- Raises:
- ValueError: If the token is empty, structurally malformed,
or cannot be decoded.