fastmcp/tests/server/auth
Jeremiah Lowin 562e51b378
Improve OAuth error messages with custom handlers and middleware (#2221)
* Enhance OAuth Proxy error responses with branded HTML pages

OAuth Proxy authentication errors now show styled HTML error pages in browsers
instead of raw JSON, with content negotiation for API clients. Enhanced error
messages explain common causes (ephemeral storage, server restarts) and provide
clear remediation steps.

Changes:
- Created enhanced authorization handler that extends SDK's AuthorizationHandler
- Created enhanced auth middleware that extends SDK's RequireAuthMiddleware
- HTML error pages use server branding (icon, name) from FastMCP instance
- Added comprehensive troubleshooting section to OAuth Proxy docs
- Added FAQ entry linking to detailed troubleshooting

* Add comprehensive tests for enhanced OAuth error responses

Tests cover:
- HTML error pages for browser requests with server branding
- Enhanced JSON responses with registration endpoint hints
- Content negotiation between HTML and JSON
- Enhanced middleware error messages for invalid_token
- WWW-Authenticate header format consistency with SDK

* Update language for new storage defaults

* update docs

* Update tests for simplified error messages

* Clean up messages
2025-10-22 21:29:14 -04:00
..
providers Replace subprocess tests with in-process async servers (#2006) 2025-10-19 10:47:54 -04:00
__init__.py Add WorkOS and Azure OAuth providers (#1550) 2025-08-20 16:22:03 -04:00
test_auth_provider.py Upgrade to MCP 1.17+ with RFC 9728 compliance (#2122) 2025-10-17 09:29:23 -04:00
test_enhanced_error_responses.py Improve OAuth error messages with custom handlers and middleware (#2221) 2025-10-22 21:29:14 -04:00
test_jwt_issuer.py OAuth proxy issues its own tokens (#2109) 2025-10-17 14:31:53 -04:00
test_jwt_provider.py Replace subprocess tests with in-process async servers (#2006) 2025-10-19 10:47:54 -04:00
test_oauth_consent_flow.py Support custom server name, icons, and link in OAuth Proxy consent page (#2135) 2025-10-18 11:49:26 -04:00
test_oauth_mounting.py Support mounting OAuth-protected servers under path prefixes (#2119) 2025-10-17 11:44:49 -04:00
test_oauth_proxy.py Replace subprocess tests with in-process async servers (#2006) 2025-10-19 10:47:54 -04:00
test_oauth_proxy_redirect_validation.py Replace subprocess tests with in-process async servers (#2006) 2025-10-19 10:47:54 -04:00
test_oauth_proxy_storage.py Add platform-aware OAuth token persistence (#2218) 2025-10-22 20:42:24 -04:00
test_oidc_proxy.py fix: Improve URL handling in OIDCConfiguration (#1850) 2025-09-19 13:11:37 -04:00
test_redirect_validation.py Fix OAuth redirect URI validation for DCR compatibility (#1661) 2025-08-28 15:19:56 -04:00
test_remote_auth_provider.py Support mounting OAuth-protected servers under path prefixes (#2119) 2025-10-17 11:44:49 -04:00
test_static_token_verifier.py Add documentation for get_access_token() dependency function (#1446) 2025-08-11 13:01:44 -04:00