Expand description
§TurboMCP Auth - Unified Authentication Framework
World-class authentication and authorization for TurboMCP with standards-compliant implementations of OAuth 2.1, JWT, API keys, and DPoP token binding.
§Design Principles
- Single Source of Truth: ONE canonical
AuthContexttype used everywhere - Feature-Gated Complexity: Simple by default, powerful when needed
- Zero-Cost Abstractions: No overhead for unused features
- Standards-Compliant: OAuth 2.1, RFC 7519 (JWT), RFC 9449 (DPoP), RFC 9728
§Key Features
- Unified AuthContext - Single type for all authentication scenarios
- OAuth 2.1 - RFC 8707/9728/7591 compliant with PKCE support
- Multi-Provider - Google, GitHub, Microsoft, GitLab out of the box
- API Key Auth - Simple and secure API key authentication
- RBAC Support - Role-based access control with fine-grained permissions
- Session Management - Flexible token storage and lifecycle management
- DPoP Support - Optional RFC 9449 proof-of-possession tokens
§Architecture
context- UnifiedAuthContexttype (THE canonical auth representation)types- Core types (UserInfo, TokenInfo, provider traits)config- Configuration types for authentication providersproviders- Authentication provider implementationsapi_key- API key authenticationoauth2- OAuth 2.1 provider
manager- Authentication manager for provider orchestrationoauth2- OAuth 2.1 client with authorization flowsserver- Server-side authentication helpers (RFC 9728 Protected Resource)
§Quick Start
use turbomcp_auth::{AuthContext, UserInfo};
use std::time::SystemTime;
use std::collections::HashMap;
// Create an auth context using the builder
let user = UserInfo {
id: "user123".to_string(),
username: "alice".to_string(),
email: Some("alice@example.com".to_string()),
display_name: Some("Alice".to_string()),
avatar_url: None,
metadata: HashMap::new(),
};
let auth = AuthContext::builder()
.subject("user123")
.user(user)
.provider("api-key")
.roles(vec!["admin".to_string(), "user".to_string()])
.permissions(vec!["write:data".to_string()])
.build()
.unwrap();
// Check authorization
if auth.has_role("admin") && auth.has_permission("write:data") {
println!("User {} has write access", auth.sub);
}§Feature Flags
§Default Features
api-key- API key authenticationoauth2- OAuth 2.1 flows and providers
§Core Authentication Methods
jwt- JWT token validationcustom- Custom auth provider support (traits only)
§Advanced Features
dpop- RFC 9449 DPoP token bindingrbac- Role-based access control helpers
§Token Lifecycle
token-refresh- Automatic token refreshtoken-revocation- Token revocation support
§Observability
metrics- Metrics collection (future)tracing-ext- Extended tracing support
§Middleware
middleware- Tower middleware support (future)
§Batteries-Included
full- All features enabled
§Standards Compliance
- RFC 7519 - JSON Web Token (JWT)
- RFC 6749 - OAuth 2.0 Authorization Framework
- RFC 7636 - Proof Key for Code Exchange (PKCE)
- RFC 8707 - OAuth 2.0 Resource Indicators
- RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession (DPoP)
- RFC 9728 - OAuth 2.0 Protected Resource Metadata
Re-exports§
pub use api_key::ApiKeyProvider;pub use oauth2::OAuth2Provider;pub use turbomcp_dpop as dpop;
Modules§
- api_key
- API Key Authentication Provider
- api_
key_ validation - Secure API Key Validation with Constant-Time Comparison
- config
- Authentication Configuration Types
- context
- Unified Authentication Context
- introspection
- OAuth 2.0 Token Introspection (RFC 7662)
- jwt
- JWT Infrastructure - Shared JWT validation and signing for TurboMCP
- manager
- Authentication Manager
- oauth2
- OAuth 2.1 Implementation
- providers
- Authentication Providers
- server
- Server-side authentication and authorization helpers
- types
- Core Authentication Types
Structs§
- Access
Token - Secure access token with metadata
- Auth
Config - Authentication configuration
- Auth
Context - Unified authentication context containing user identity, claims, and session metadata.
- Auth
Context Builder - Builder for constructing
AuthContext - Auth
Manager - Authentication manager for coordinating multiple authentication providers
- Auth
Provider Config - Authentication provider configuration
- Authorization
Config - Authorization configuration
- Client
Registration Error - Client Registration Error Response (RFC 7591)
- Client
Registration Request - Dynamic Client Registration Request (RFC 7591)
- Client
Registration Response - Dynamic Client Registration Response (RFC 7591)
- Default
Auth Middleware - Default authentication middleware
- Device
Authorization Response - Device authorization response for CLI/IoT flows
- Dpop
Config - DPoP (Demonstration of Proof-of-Possession) configuration
- Dynamic
Client Registration - Dynamic Client Registration Manager for RFC 7591 compliance
- McpResource
Registry - MCP Server Resource Registry for RFC 9728 compliance
- OAuth2
Auth Result - OAuth 2.1 authorization result
- OAuth2
Config - OAuth 2.1 configuration
- Protected
Resource Metadata - Protected Resource Metadata (RFC 9728) for server-side discovery
- Provider
Config - Provider-specific configuration for handling OAuth quirks
- Token
Info - Token information
- User
Info - User information
- Validation
Config - Validation configuration for AuthContext
Enums§
- Application
Type - Application type for OAuth client (RFC 7591)
- Auth
Credentials - Authentication credentials
- Auth
Provider Type - Authentication provider types
- Bearer
Token Method - Bearer token delivery methods (RFC 9728)
- Client
Registration Error Code - Client Registration Error Codes (RFC 7591)
- Dpop
KeyStorage Config - DPoP key storage configuration
- OAuth2
Flow Type - OAuth 2.1 flow types
- Provider
Type - OAuth2 provider types with built-in configurations
- Refresh
Behavior - Token refresh behavior strategies
- Security
Level - Security levels for OAuth 2.1 flows
Traits§
- Auth
Middleware - Authentication middleware trait
- Auth
Provider - Authentication provider trait
- Token
Storage - Secure token storage abstraction