When to Use
Organizations with existing identity providers (Okta, Auth0, Azure AD, Cognito) can use JWT validation. Users authenticate through the IdP, and MCP access works the same way. Flow:- Users get a token from the IdP
- Token included in MCP requests
- Portkey validates the token against the IdP
- Valid requests proceed with user identity attached
Validation Methods
Configure one validation method per MCP server. Each has different tradeoffs.JWKS URI
Fetch public keys from your IdP’s JWKS endpoint. This is the standard approach for most identity providers.Inline JWKS
Embed public keys directly in the configuration. Use for self-contained deployments or environments without a JWKS endpoint.Token Introspection (RFC 7662)
For opaque tokens that require real-time validation. Portkey calls your IdP’s introspection endpoint.active boolean field per RFC 7662.
Best for: Opaque tokens, real-time revocation checking, or validating token status against the IdP on every request.
Configuration Reference
Core Options
| Field | Type | Default | Description |
|---|---|---|---|
jwksUri | string | - | URL to fetch public keys |
jwks | object | - | Inline JWKS object with keys array |
introspectEndpoint | string | - | Token introspection URL (RFC 7662) |
headerKey | string | "Authorization" | Header to read the token from |
algorithms | string[] | ["RS256"] | Allowed signing algorithms |
Timing Options
| Field | Type | Default | Description |
|---|---|---|---|
clockTolerance | number | 5 | Clock skew tolerance in seconds |
cacheMaxAge | number | 86400 | JWKS cache TTL in seconds (24 hours) |
maxTokenAge | string | - | Max token age (e.g., "30m", "12h") |
Introspection Options
| Field | Type | Default | Description |
|---|---|---|---|
introspectEndpoint | string | - | Token introspection URL |
introspectContentType | string | "application/json" | Content-Type for introspection requests |
introspectCacheMaxAge | number | - | Cache introspection results (seconds) |
Claim Validation Options
| Field | Type | Default | Description |
|---|---|---|---|
requiredClaims | string[] | - | Claims that must be present |
claimValues | object | - | Expected claim values with match types |
headerPayloadMatch | string[] | - | Header claims that must match payload claims |
Custom Token Header
By default, Portkey reads the token from theAuthorization header. For a different header:
Require Specific Claims
Tokens must include these claims or they’re rejected:sub, email, or groups, Portkey returns:
Validate Claim Values
Check that claims have expected values:Match Types
| Type | Description | Example |
|---|---|---|
exact | Value must match exactly | iss must equal "https://your-idp.com" |
contains | Payload must include at least one value (OR) | aud must include "api" OR "mcp" OR "portkey" |
containsAll | Payload must include all values (AND) | scope must include "mcp:read" AND "mcp:write" |
regex | Match against a regular expression | email must match @yourcompany\.com$ |
Header-Payload Matching
Ensure that claims in the JWT header match claims in the payload. This provides additional security for tokens that include claims in both locations.Caching Behavior
JWKS Caching
- Keys cached for 24 hours by default (configurable via
cacheMaxAge) - CryptoKeys are pre-imported and cached for performance
- If signature verification fails with a cached key, Portkey refetches the JWKS (handles key rotation)
Introspection Caching
- Not cached by default (every request calls the introspection endpoint)
- Enable caching with
introspectCacheMaxAge(in seconds) - Cached results respect token expiry—expired tokens aren’t served from cache
- First request: calls introspection endpoint, caches result
- Subsequent requests (within 5 minutes): uses cached result
- After 5 minutes: calls introspection endpoint again
Performance Optimizations
Portkey optimizes JWT validation for production workloads:| Optimization | Description |
|---|---|
| Fail-fast expiry check | Checks token expiry before expensive signature verification |
| JWKS caching | Keys cached and pre-imported as CryptoKeys |
| Key rotation handling | Auto-refetch JWKS if key not found |
| Introspection caching | Optional caching of introspection results |
- JWKS (cache hit): < 1ms
- JWKS (cache miss): 50-200ms (network fetch)
- Introspection (uncached): 50-300ms (depends on IdP)
- Introspection (cached): < 1ms
Example: Okta Integration
Example: Auth0 Integration
Example: Azure AD Integration
Combining with Identity Forwarding
JWT validation extracts user claims from the token. Identity forwarding passes those claims to MCP servers:- User sends request with IdP token
- Portkey validates token, extracts claims
- Portkey forwards claims to MCP server
- MCP server uses claims for authorization/logging
Error Responses
| Error | Description |
|---|---|
Missing Authorization header | No token provided |
Invalid authorization header format | Not in Bearer <token> format |
JWT validation failed | Signature invalid or token malformed |
Token is expired | Token’s exp claim is in the past |
Token is not yet valid | Token’s nbf claim is in the future |
Missing required claims: <claims> | Token missing required claims |
Token is not active | Introspection returned active: false |
Related
| Topic | Description |
|---|---|
| External OAuth | Overview of using external IdPs |
| Identity Forwarding | Pass validated claims to MCP servers |

