Skip to content

Introduce RemoteAuthProvider for cleaner external identity provider integration, update docs - #1346

Merged
jlowin merged 6 commits into
mainfrom
auth2
Aug 3, 2025
Merged

Introduce RemoteAuthProvider for cleaner external identity provider integration, update docs#1346
jlowin merged 6 commits into
mainfrom
auth2

Conversation

@jlowin

@jlowin jlowin commented Aug 3, 2025

Copy link
Copy Markdown
Member

This enhancement introduces RemoteAuthProvider, a new base class that simplifies integration with external identity providers by composing token verification with OAuth discovery metadata. This creates standardized OAuth 2.0 Protected Resource endpoints while maintaining clean separation of concerns.

The new architecture makes it easier to build authentication providers that work with external identity services. RemoteAuthProvider handles OAuth metadata generation and MCP protocol integration, while delegating token validation to configurable underlying verifiers.

New RemoteAuthProvider pattern:

from fastmcp import FastMCP
from fastmcp.server.auth.providers.jwt import JWTVerifier
from fastmcp.server.authimport RemoteAuthProvider

token_verifier = JWTVerifier(
    jwks_uri="https://auth.example.com/.well-known/jwks.json",
    issuer="https://auth.example.com"
)

auth = RemoteAuthProvider(
    token_verifier=token_verifier,
    authorization_servers=["https://auth.example.com"],
    resource_server_url="https://your-mcp-server.com"
)

mcp = FastMCP(auth=auth)

Key enhancements:

  • New RemoteAuthProvider base class composes token verification with OAuth metadata
  • AuthKitProvider refactored to inherit from RemoteAuthProvider for better architecture
  • Consolidated resource server URL configuration across authentication patterns
  • Streamlined HTTP server authentication integration with cleaner get_routes() pattern
  • Enhanced documentation with clearer guidance on authentication responsibility levels

The changes maintain full backward compatibility while providing a cleaner foundation for building custom external identity provider integrations.

jlowin added 5 commits August 2, 2025 12:08
…raction

- Replace customize_routes([]) with clean get_routes() method
- Remove confusing setup_auth_middleware_and_routes() helper function
- Inline auth setup logic directly in create_sse_app and create_streamable_http_app
- Simplify AuthProvider base class with optional required_scopes
- Add RemoteAuthProvider for TokenVerifier + OAuth metadata composition
- Update all auth providers to use new get_routes() interface
- Remove unused resource_server_url parameters from app creators
- Delete obsolete test_auth_setup.py since helper function removed

Benefits:
- Cleaner API: get_routes() tells exactly what it does
- Less abstraction: Eliminated confusing 4-tuple return
- Better separation of concerns: Each provider owns its routes
- More readable: Inline logic is clearer than mystery functions
- Composable design: TokenVerifier + metadata = RemoteAuthProvider
- AuthKitProvider is now a clean RemoteAuthProvider subclass
- Override get_oauth_authorization_server_routes() for AuthKit metadata forwarding
- Add get_oauth_authorization_server_routes() and get_protected_resource_routes() to RemoteAuthProvider
- get_routes() now combines both OAuth authorization server and protected resource routes
- Eliminate code duplication: AuthKitProvider no longer needs to implement get_routes()
- Clean composition pattern: TokenVerifier + metadata + OAuth endpoints = RemoteAuthProvider

Benefits:
- AuthKitProvider is now just RemoteAuthProvider + OAuth metadata forwarding
- Reusable pattern for other providers that need both protected resource and OAuth metadata
- Standardized route creation using MCP SDK's create_protected_resource_routes()
- Clean inheritance hierarchy with clear separation of concerns
@jlowin jlowin added the feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues. label Aug 3, 2025
@github-actions github-actions Bot added documentation Updates to docs, examples, or guides. Primary change is documentation-related. tests http Related to HTTP transport, networking, or web server functionality. labels Aug 3, 2025
@jlowin jlowin added auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. and removed http Related to HTTP transport, networking, or web server functionality. labels Aug 3, 2025
@jlowin
jlowin merged commit ec52e74 into main Aug 3, 2025
11 checks passed
@jlowin
jlowin deleted the auth2 branch August 3, 2025 00:36
@taylorwilsdon

Copy link
Copy Markdown
Contributor

Any plans to tie this in more directly with the session context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. documentation Updates to docs, examples, or guides. Primary change is documentation-related. feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants