Client Authentication¶
private_key_jwt client authentication (RFC 7523) for OAuth 2.0 token
endpoints. Clients sign a JWT with their private key and submit it as a
client_assertion; JWTClientAuthenticator verifies it against a public key
resolved through a pluggable JWKSProvider, with an asymmetric-only algorithm
allowlist and jti replay protection.
For a shared replay cache, pass any object satisfying
mcp_authflow.client_auth.AsyncRedisClient. This protocol requires only
the Redis SET operation used by replay protection; it is intentionally
separate from the sorted-set protocol used by the rate limiter.
client_auth
¶
Client authentication primitives for OAuth 2.0 token endpoints.
Currently provides private_key_jwt (RFC 7523) verification. The package
exposes the high-level :class:JWTClientAuthenticator, the
:class:JWKSProvider integration point, and the algorithm allowlist /
blocklist constants for callers that need them.
AsyncRedisClient
¶
Bases: Protocol
Minimal async Redis interface used for JTI replay-cache storage.
JWKSProvider
¶
Bases: Protocol
Resolve a client's JWKS by client_id.
Implementations choose how to look up the key material — static dict,
Dynamic Client Registration record, Client ID Metadata Document, etc.
Returning None signals "no keys available" and causes authentication
to fail with :class:JWTAuthError.
JWTAuthError
¶
Bases: Exception
Raised when private_key_jwt client authentication fails.
JWTClientAuthenticator
¶
JWTClientAuthenticator(
token_endpoint: str,
jwks_provider: JWKSProvider,
redis: AsyncRedisClient | None = None,
)
Verify private_key_jwt client assertions per RFC 7523.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_endpoint
|
str
|
The token endpoint URL, used as the expected
|
required |
jwks_provider
|
JWKSProvider
|
Resolves the client's JWKS by |
required |
redis
|
AsyncRedisClient | None
|
Optional async Redis client for a persistent / shared JTI
replay cache. When |
None
|
Source code in mcp_authflow/client_auth/jwt.py
authenticate
async
¶
Authenticate a client using private_key_jwt.
Returns True on success and raises :class:JWTAuthError otherwise.
Rejections are logged at WARNING before the error propagates, so an
operator watching this logger sees failed attempts (replay detection,
blocked algorithms, ...) and not just successes.