Troubleshooting Guide

Common issues and solutions when using oauth-mcp-proxy.


Authentication Errors

"Authentication required: missing OAuth token"

Cause: Token not extracted from HTTP request

Solutions:

  1. Check Authorization header present:

# Make sure you're sending the header
curl -H "Authorization: Bearer <token>" https://server.com/mcp
  1. Verify CreateHTTPContextFunc configured:

streamable := mcpserver.NewStreamableHTTPServer(
    mcpServer,
    mcpserver.WithHTTPContextFunc(oauth.CreateHTTPContextFunc()),  // Required!
)
  1. Check header format:

✅ Authorization: Bearer eyJhbGc...
❌ Authorization: eyJhbGc...       (missing "Bearer ")
❌ authorization: Bearer ...       (lowercase - case-sensitive!)

"Authentication failed: invalid token"

Cause: Token validation failed

Check:

  1. Token not expired:

  1. Issuer matches:

  1. Audience matches:

  1. Signature valid (HMAC):

  1. Provider reachable (OIDC):

Debug:


Configuration Errors

"invalid config: provider is required"

Cause: Missing or empty Provider field

Solution:


"invalid config: JWTSecret is required for HMAC provider"

Cause: Using HMAC provider without JWTSecret

Solution:


"invalid config: Issuer is required for OIDC provider"

Cause: Using Okta/Google/Azure without Issuer

Solution:


"invalid config: proxy mode requires ClientID"

Cause: Mode is "proxy" but ClientID not provided

Solution:


Provider Errors

"Failed to initialize OIDC provider"

Cause: Cannot connect to OAuth provider's discovery endpoint

Check:

  1. Issuer URL correct:

  1. Network connectivity:

  1. Firewall/proxy:

  • Check corporate firewall allows outbound HTTPS

  • Check proxy settings if behind corporate proxy

Debug:


Redirect URI Errors

"Invalid redirect URI" (Native Mode)

Cause: Client redirect is not localhost (security protection)

Fixed redirect mode only allows localhost:

Why: Prevents open redirect attacks in fixed redirect mode.

Solution: Use allowlist mode if you need non-localhost redirects:


"redirect_uri_mismatch" (Provider Error)

Cause: Redirect URI not configured in OAuth provider

Solutions:

Okta:

  1. Go to Applications → Your App → General

  2. Add to "Sign-in redirect URIs"

  3. Must match exactly (including trailing slash if present)

Google:

  1. Cloud Console → Credentials → OAuth 2.0 Client

  2. Add to "Authorized redirect URIs"

  3. Exact match required

Azure:

  1. App registrations → Your App → Authentication

  2. Add to "Redirect URIs"

  3. Must match exactly


Token Caching Issues

Tokens Not Being Cached

Expected: Second request with same token should be faster (cache hit)

Check:

  1. Cache logs:

  1. Cache TTL: 5 minutes (hardcoded in v0.1.0)

  2. Cache scope: Per Server instance

Debug:

  • Different Server instances = different caches

  • Token modified between requests = new cache entry

  • Token expired = cache miss

Metrics:


Runtime Errors

Panic: "invalid memory address or nil pointer dereference"

Cause: Usually missing logger in test code or direct handler creation

Solution:


"Token exchange failed"

Cause: OAuth provider rejected token exchange request

Check:

  1. Authorization code valid:

  • Code must be unused (single-use only)

  • Code must not be expired (typically 10 minutes)

  1. PKCE parameters match:

  1. Redirect URI matches:

  1. Client credentials valid:

Debug:

  • Check OAuth provider logs (Okta/Google/Azure admin consoles)

  • Look for specific error codes in provider response


Performance Issues

Slow Authentication

Expected latency:

  • Cache hit: <5ms

  • Cache miss (HMAC): <10ms

  • Cache miss (OIDC): <100ms (network call to provider)

If slower:

  1. OIDC discovery slow:

  • First request does OIDC discovery (fetches .well-known/openid-configuration)

  • Cached after first request

  • Network latency to provider affects first request

  1. JWKS fetch slow:

  • OIDC validator fetches public keys on initialization

  • Check network latency to OAuth provider

Solutions:

  • Warm up on server start (make a test validation call)

  • Check network connectivity to OAuth provider

  • Consider caching OIDC discovery (future enhancement)


Development vs Production

Works Locally, Fails in Production

Common causes:

  1. HTTPS not configured:

  1. Secrets not in environment:

  1. Provider can't reach callback URL:

  • ServerURL must be publicly accessible

  • Firewall must allow inbound HTTPS

  • DNS must resolve correctly

  1. Redirect URI mismatch:

  • Localhost works in dev, but production URL different

  • Update OAuth provider redirect URIs for production domain


Debugging Tips

Enable Verbose Logging

Check OAuth Metadata

Decode JWT Token

Test Token Manually


Still Having Issues?

  1. Check logs: Look for ERROR and WARN level messages

  2. Verify configuration: Review CONFIGURATION.md

  3. Check provider setup: Review provider-specific guide in providers/arrow-up-right

  4. Security check: Review SECURITY.md

  5. GitHub Issues: Search or create issue at github.com/tuannvm/oauth-mcp-proxy/issuesarrow-up-right


Common Patterns

Multiple OAuth Providers

Custom Token Claims

Currently, oauth-mcp-proxy extracts:

  • sub → User.Subject

  • email → User.Email

  • preferred_username → User.Username (fallback to email or sub)

For custom claims, access the raw token:


Getting Help

Last updated

Was this helpful?