fastmcp.server.auth.providers.jwt
TokenVerifier implementations for FastMCP.
Classes
JWKData
JSON Web Key data structure.
JWKSData
JSON Web Key Set data structure.
RSAKeyPair
RSA key pair for JWT testing.
Methods:
generate
- Generated key pair
create_token
subject
: Subject claim (usually user ID)issuer
: Issuer claimaudience
: Audience claim - can be a string or list of strings (optional)scopes
: List of scopes to includeexpires_in_seconds
: Token expiration time in secondsadditional_claims
: Any additional claims to includekid
: Key ID to include in header
JWTVerifierSettings
Settings for JWT token verification.
JWTVerifier
JWT token verifier supporting both asymmetric (RSA/ECDSA) and symmetric (HMAC) algorithms.
This verifier validates JWT tokens using various signing algorithms:
- Asymmetric algorithms (RS256/384/512, ES256/384/512, PS256/384/512): Uses public/private key pairs. Ideal for external clients and services where only the authorization server has the private key.
- Symmetric algorithms (HS256/384/512): Uses a shared secret for both signing and verification. Perfect for internal microservices and trusted environments where the secret can be securely shared.
- You have JWT tokens issued by an external service (asymmetric)
- You need JWKS support for automatic key rotation (asymmetric)
- You have internal microservices sharing a secret key (symmetric)
- Your tokens contain standard OAuth scopes and claims
load_access_token
token
: The JWT token string to validate
- AccessToken object if valid, None if invalid or expired
verify_token
token
: The JWT token string to validate
- AccessToken object if valid, None if invalid or expired
StaticTokenVerifier
Simple static token verifier for testing and development.
This verifier validates tokens against a predefined dictionary of valid token
strings and their associated claims. When a token string matches a key in the
dictionary, the verifier returns the corresponding claims as if the token was
validated by a real authorization server.
Use this when:
- You’re developing or testing locally without a real OAuth server
- You need predictable tokens for automated testing
- You want to simulate different users/scopes without complex setup
- You’re prototyping and need simple API key-style authentication