fastmcp.server.auth.jwt_issuer
JWT token issuance and verification for FastMCP OAuth Proxy.
This module implements the token factory pattern for OAuth proxies, where the proxy
issues its own JWT tokens to clients instead of forwarding upstream provider tokens.
This maintains proper OAuth 2.0 token audience boundaries.
Functions
derive_jwt_key
upstream_secret
: The OAuth client secret from upstream providerserver_salt
: Random salt unique to this server instance
- 32-byte key suitable for HS256 JWT signing
derive_encryption_key
upstream_secret
: The OAuth client secret from upstream provider
- 32-byte Fernet key (base64url-encoded)
derive_key_from_secret
secret
: User-provided secret (any string or bytes)salt
: Application-specific salt stringinfo
: Key purpose identifier
- 32-byte key suitable for HS256 JWT signing or Fernet encryption
Classes
JWTIssuer
Issues and validates FastMCP-signed JWT tokens using HS256.
This issuer creates JWT tokens for MCP clients with proper audience claims,
maintaining OAuth 2.0 token boundaries. Tokens are signed with HS256 using
a key derived from the upstream client secret.
Methods:
issue_access_token
client_id
: MCP client IDscopes
: Token scopesjti
: Unique token identifier (maps to upstream token)expires_in
: Token lifetime in seconds
- Signed JWT token
issue_refresh_token
client_id
: MCP client IDscopes
: Token scopesjti
: Unique token identifier (maps to upstream token)expires_in
: Token lifetime in seconds (should match upstream refresh expiry)
- Signed JWT token
verify_token
token
: JWT token to verify
- Decoded token payload
JoseError
: If token is invalid, expired, or has wrong claims
TokenEncryption
Handles encryption/decryption of upstream OAuth tokens at rest.
Methods:
encrypt
token
: Plain text token
- Encrypted token bytes
decrypt
encrypted_token
: Encrypted token bytes
- Plain text token
cryptography.fernet.InvalidToken
: If token is corrupted or key is wrong