docs/python-sdk/fastmcp-server-auth-providers-jwt.mdx
fastmcp.server.auth.providers.jwtTokenVerifier implementations for FastMCP.
JWKData <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L27" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>JSON Web Key data structure.
JWKSData <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L40" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>JSON Web Key Set data structure.
RSAKeyPair <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L47" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>RSA key pair for JWT testing.
Methods:
generate <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>generate(cls) -> RSAKeyPair
Generate an RSA key pair for testing.
Returns:
create_token <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L89" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_token(self, subject: str = 'fastmcp-user', issuer: str = 'https://fastmcp.example.com', audience: str | list[str] | None = None, scopes: list[str] | None = None, expires_in_seconds: int = 3600, additional_claims: dict[str, Any] | None = None, kid: str | None = None) -> str
Generate a test JWT token for testing purposes.
Args:
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 headerJWTVerifier <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L156" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>JWT token verifier supporting both asymmetric (RSA/ECDSA) and symmetric (HMAC) algorithms.
This verifier validates JWT tokens using various signing algorithms:
Use this when:
Methods:
load_access_token <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L397" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>load_access_token(self, token: str) -> AccessToken | None
Validate a JWT bearer token and return an AccessToken when the token is valid.
Args:
token: The JWT bearer token string to validate.Returns:
None if the token is expired, has an invalid signature or format, fails issuer/audience/scope validation, or any other validation error occurs.verify_token <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L523" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>verify_token(self, token: str) -> AccessToken | None
Verify a bearer token and return access info if valid.
This method implements the TokenVerifier protocol by delegating to our existing load_access_token method.
Args:
token: The JWT token string to validateReturns:
StaticTokenVerifier <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L539" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>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:
WARNING: Never use this in production - tokens are stored in plain text!
Methods:
verify_token <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/auth/providers/jwt.py#L573" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>verify_token(self, token: str) -> AccessToken | None
Verify token against static token dictionary.