π v1.8.0 - OAuth Auth Context & Complete Middleware Architecture
π BREAKING CHANGE: OAuth Auth Context Pass-Through
This release completes the production-ready OAuth authentication flow with full token pass-through from transport layer to tool execution.
β¨ What's New
π― Production-Ready OAuth Flow:
- β
New Parameter:
ProtocolHandler::handle_request()now acceptsauth_context: Option<AuthContext> - β
Transport Integration:
StreamableHttpServerextracts and validates OAuth from Authorization headers - β
Middleware Pattern: Tool middleware can inject tokens into
RequestHandlerExtrametadata - β DRY Tools: No repetitive auth code - tools consume tokens from metadata
- β
Fine-Grained Access:
ToolAuthorizertrait for per-tool authorization
ποΈ Three-Layer Middleware Architecture:
- πΉ HTTP Layer (
ServerHttpMiddleware) - Transport-level processing - πΉ Protocol Layer (
EnhancedMiddleware) - JSON-RPC message processing - πΉ Tool Layer (
ToolMiddleware) - Tool execution processing - Full auth context pass-through across all layers
π New Examples & Tests
- Example 58: Complete OAuth flow from transport β middleware β tools
- Example 55: Server HTTP middleware demonstration
- Integration Tests:
tests/auth_context_integration_test.rswith 3 scenarios- Auth context flows from transport to tools
- Missing auth context fails in tool
- Invalid token rejected at transport
β οΈ Migration Required
All ProtocolHandler::handle_request() calls must now include auth_context parameter:
// Update existing calls - add None for no authentication:
server.handle_request(id, request, None).await
// In transport layer (e.g., HTTP handlers):
let auth_context = auth_provider.validate_request(auth_header).await?;
server.handle_request(id, request, auth_context).awaitAffected Files:
- All transport adapters (
StdioAdapter,HttpAdapter,WebSocketAdapter) - Custom
ProtocolHandlerimplementations - Test code calling
handle_request()
π¨ Technical Details
Core Changes:
src/server/core.rs: Addedauth_contextparameter toProtocolHandlertraitsrc/server/mod.rs: UpdatedServerwrapper with auth validationsrc/server/streamable_http_server.rs: OAuth extraction and validationsrc/server/adapters.rs: Updated all transport adapters
Quality Assurance:
- β Zero clippy warnings
- β All 439+ tests passing
- β Integration tests for complete OAuth flow
- β Example code demonstrates best practices
- β Cognitive complexity reduced (β€25 per function)
π― Use Cases Enabled
- Multi-tenant SaaS: Each tool call includes user context
- Backend API Integration: Tools authenticate with third-party APIs using user tokens
- Fine-grained Authorization: Per-user, per-tool access control
- Audit Logging: Track which user called which tool with what token
π Documentation
- README updated with v1.8.0 migration guide
- All examples updated to pass
auth_context - API docs include auth_context usage patterns
Full Changelog: v1.7.0...v1.8.0
Contributors: @guyernest
Quality Gates: β All passing (formatting, clippy, tests, benchmarks)