Skip to main content

Overview

Secure MCP Gateway provides comprehensive OAuth 2.0 and 2.1 support for authenticating with remote MCP servers. This includes client credentials flow, mutual TLS (mTLS), automatic token management, and secure token caching.

Supported Features

OAuth 2.0 & 2.1

Full specification compliance with security best practices

Client Credentials

Server-to-server authentication flow

Mutual TLS (mTLS)

Enhanced security with client certificates (RFC 8705)

Token Caching

Automatic caching with proactive refresh

Token Revocation

RFC 7009 compliant token revocation

Scope Validation

Verifies returned tokens have requested scopes

Retry Logic

Exponential backoff for transient failures

Metrics & Monitoring

Comprehensive tracking of OAuth operations

Quick Start

Basic OAuth 2.1 Setup

1

Obtain OAuth Credentials

Get your client ID and secret from your OAuth provider (Auth0, Okta, Keycloak, etc.)
2

Add Server with OAuth

3

Configure OAuth

Edit ~/.enkrypt/enkrypt_mcp_config.json and add OAuth config:
4

Test Connection

Restart Claude Desktop and test:

Configuration Reference

Minimal Configuration

Complete Configuration

Configuration Fields

Core Settings

*Required when enabled: true

Server Detection

The gateway auto-detects remote servers by checking for npx, mcp-remote, curl, or http(s):// in command/args. Set is_remote: true explicitly to avoid false detection.

Scope & Audience

Security Settings

OAuth 2.1 Compliance
  • Requires OAUTH_ENFORCE_HTTPS: true
  • Recommends OAUTH_USE_BASIC_AUTH: true
  • Enforces OAUTH_TOKEN_IN_HEADER_ONLY: true

Token Management

How Token Refresh Works:
1

Token Acquired

Token obtained with expires_in: 3600 (1 hour)
2

Cached with Expiry

Cached with expires_at timestamp
3

Proactive Refresh

Refreshed when expires_at - 300s < now (5 min before expiry)
4

Automatic Retry

On failure, retry with exponential backoff (2s, 4s, 8s)

Mutual TLS (mTLS)

What is mTLS?

Mutual TLS provides enhanced security by requiring both client and server to present certificates during the TLS handshake. This is specified in RFC 8705.

Setting Up mTLS

1

Generate Client Certificate

Generate a client certificate and private key:
2

Upload Certificate to OAuth Provider

Register your client certificate with your OAuth provider (Auth0, Okta, etc.)
3

Configure Gateway

4

Test Connection

The gateway will automatically use the certificate for all OAuth requests.
Certificate Security
  • Store certificates in secure directory with chmod 600
  • Never commit certificates to version control
  • Rotate certificates before expiry
  • Use different certificates for different environments

Token Injection

For Remote Servers

Tokens are automatically injected as HTTP headers:
The gateway handles this automatically when is_remote: true.

For Local Servers

Tokens are injected as environment variables:
Your MCP server can read these variables to authenticate with remote APIs.

Provider-Specific Examples

Auth0

Okta

Keycloak

GitHub Apps (mTLS)

Monitoring & Troubleshooting

Enable Debug Logging

Logs will show:

Common Errors

Solution: Verify OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET are correct
Solution: Use https:// URL or set OAUTH_VERSION: "2.0"
Solution: Verify certificate path and file permissions (chmod 600)
Solution: Request correct scopes or set OAUTH_VALIDATE_SCOPES: false
Info: Automatic retry with exponential backoff (2s, 4s, 8s)

Viewing Metrics

OAuth metrics are available programmatically:

Security Best Practices

Use OAuth 2.1

OAuth 2.1 has stricter security requirements and removes deprecated features

Enable HTTPS

Always use HTTPS for token URLs in production

Use Basic Auth

Prefer client_secret_basic over client_secret_post

Validate Scopes

Always verify returned tokens have requested scopes

Enable mTLS

Use mutual TLS for high-security environments

Rotate Secrets

Regularly rotate client secrets and certificates

Minimal Scopes

Request only the scopes you need (principle of least privilege)

Secure Storage

Store certificates with proper permissions (chmod 600)

Security Checklist

HTTPS Enforced

OAUTH_ENFORCE_HTTPS: true for production

Scope Validation Enabled

OAUTH_VALIDATE_SCOPES: true

Credentials Not Committed

Add .enkrypt/ to .gitignore

Certificates Secured

chmod 600 on all certificate files

Different Creds per Environment

Separate client IDs for dev/staging/prod

Monitoring Enabled

Track OAuth metrics and failures

Advanced Topics

Token Revocation

Revoke tokens programmatically:

Force Token Refresh

Invalidate Cached Token

FAQ

Not yet. Only client credentials grant is currently supported. Authorization code grant will be added in a future release.
Set is_remote: true explicitly in oauth_config. Auto-detection checks for npx, mcp-remote, curl, or http(s):// in command/args.
Yes! Tokens are injected as environment variables for stdio servers.
Proactively, 5 minutes (300s) before expiry by default. Configurable via OAUTH_TOKEN_EXPIRY_BUFFER.
Yes. mTLS is optional and disabled by default.
Automatic retry with exponential backoff (3 attempts: 2s, 4s, 8s). After exhaustion, returns error.
No. Each server has its own cached token, keyed by server_name and config_id.

Next Steps

Add MCP Servers

Learn how to add and configure MCP servers

Configure Guardrails

Add security layers to OAuth-protected servers

External Cache

Improve token caching with Redis/KeyDB

Custom Plugins

Create custom auth providers