Skip to main content

Overview

Secure MCP Gateway provides comprehensive OAuth 2.0 and OAuth 2.1 support for authenticating with remote MCP servers. The OAuth service handles token acquisition, caching, refresh, and revocation with full compliance to RFC specifications.

Features

OAuth 2.0 & 2.1

Full spec compliance with security best practices

Client Credentials

Server-to-server authentication flow

Mutual TLS (mTLS)

Client certificate authentication (RFC 8705)

Token Caching

Automatic caching with expiration tracking

Proactive Refresh

Tokens refreshed 5 minutes before expiry

Scope Validation

Verifies tokens have requested scopes

Architecture

The OAuth service consists of several specialized components:

OAuth Configuration

OAuthConfig Data Model

src/secure_mcp_gateway/services/oauth/models.py

Server Configuration Example

OAuthService Implementation

Token Acquisition

src/secure_mcp_gateway/services/oauth/oauth_service.py

Client Credentials Flow with Retry

src/secure_mcp_gateway/services/oauth/oauth_service.py

Token Execution with mTLS Support

src/secure_mcp_gateway/services/oauth/oauth_service.py

Token Management

TokenManager

src/secure_mcp_gateway/services/oauth/token_manager.py

Client Integration

The gateway automatically injects OAuth tokens into MCP server connections:
src/secure_mcp_gateway/services/oauth/integration.py

OAuth Metrics

The OAuth service tracks comprehensive metrics:
src/secure_mcp_gateway/services/oauth/metrics.py

Security Best Practices

HTTPS Only: OAuth 2.1 requires HTTPS for all token endpoints. Set enforce_https: true to validate.
Token Storage: Tokens are stored in memory only. For multi-instance deployments, consider external cache with encryption.
mTLS Certificates: Store client certificates securely and rotate regularly. Never commit certificates to source control.

Testing OAuth Configuration

Use the echo OAuth test server to verify configuration:
bad_mcps/echo_oauth_mcp.py