When to Use
Organizations with existing IdPs can use External OAuth. Users authenticate through the IdP for other services, and MCP access works the same way. Common scenarios:- SSO for internal developers. Engineers use corporate credentials to access MCP servers
- B2B applications. Your customers authenticate through their own IdP
- Compliance requirements. Mandate use of your own identity infrastructure
- No Portkey accounts. Users who arenât in Portkey need MCP access
How It Works
Configuration
Configure JWT validation for your MCP server. Portkey validates incoming tokens using your IdPâs public keys or introspection endpoint.Option 1: JWKS URI (Recommended)
The most common setup. Portkey fetches public keys from your IdPâs JWKS endpoint.- Portkey fetches and caches your IdPâs public keys
- Keys are cached for 24 hours by default
- If a key rotates, Portkey automatically refetches
- Validation happens locally (no network call per request)
Option 2: Token Introspection
For opaque tokens requiring real-time validation, or for immediate revocation.- Portkey calls your IdPâs introspection endpoint
- Response is cached for the configured duration (default: no caching)
- With
introspectCacheMaxAge: 300, results are cached for 5 minutes
- No cache: Every request calls introspection endpoint (slower, but immediate revocation)
- With cache: Better performance, but revocation takes up to cache TTL to take effect
Client Configuration
Agents include the IdP token instead of a Portkey API key:- Python
- TypeScript
Validating Claim Values
Validate that tokens are issued by the correct IdP and intended for MCP access:- Tokens from other IdPs being accepted
- Tokens intended for other services being used for MCP
Combining with Identity Forwarding
External OAuth pairs naturally with identity forwarding. Portkey validates the incoming JWT, extracts user claims, and forwards them to MCP servers.- Authorization: Check if user belongs to required groups
- Logging: Audit trail with user identity
- Personalization: Customize responses based on user
IdP-Specific Examples
Okta
- Create an authorization server in Okta Admin Console
- Create an OAuth application (Web or SPA)
- Note your issuer URL (e.g.,
https://dev-12345.okta.com/oauth2/default)
Auth0
- Create an API in Auth0 Dashboard
- Note your tenant domain and API identifier
Azure AD / Entra ID
- Register an application in Azure Portal
- Note your tenant ID and client ID
AWS Cognito
- Create a User Pool in AWS Console
- Note your region and pool ID
Securing Your Setup
Validate Issuer and Audience
Always configureclaimValues to verify iss and aud:
Require Essential Claims
Require essential claims:Use Short Token Lifetimes
Configure the IdP to issue short-lived access tokens (15-60 minutes). This limits the window if a token is compromised.Troubleshooting
âInvalid issuerâ Error
The tokenâsiss claim doesnât match your configuration. Verify the issuer URL exactly matchesâincluding trailing slashes.
âMissing required claimsâ Error
The token doesnât include claims you specified inrequiredClaims. Check your IdPâs token configuration and scopes.
âInvalid audienceâ Error
The tokenâsaud claim doesnât match your configuration. Verify the correct API identifier or client ID.
âJWKS fetch failedâ Error
Portkey couldnât fetch keys from your JWKS URI. Verify the URL is accessible and returns valid JWKS JSON.Related
| Topic | Description |
|---|---|
| JWT Validation | Full configuration reference for JWT validation |
| Identity Forwarding | Pass validated claims to MCP servers |
| Authentication Overview | Understanding gateway authentication |

