Skip to content

Commit a3918eb

Browse files
committed
fix: place well-known discovery route per RFC 8414 3.1
The .well-known/oauth-authorization-server route was prefixed with the issuer's base path *after* the well-known suffix (e.g. /custom/path/.well-known/oauth-authorization-server), which RFC 8615 3 does not recognize as a well-known URI. RFC 8414 3.1 requires the suffix to be inserted between the authority and the path component instead: /.well-known/oauth-authorization-server/custom/path. The /authorize, /token, /register, /revoke routes are unaffected - they're plain URLs under the issuer's namespace, not well-known URIs.
1 parent fd2d465 commit a3918eb

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/mcp/server/auth/routes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ def create_auth_routes(
9696
# where the client runs in a web browser.
9797
routes = [
9898
Route(
99-
issuer_path + "/.well-known/oauth-authorization-server",
99+
# RFC 8414 3.1: the well-known suffix goes between the authority and
100+
# the issuer's path component, not after it — "/custom/path/.well-known/..."
101+
# is not a valid well-known URI per RFC 8615 3.
102+
"/.well-known/oauth-authorization-server" + issuer_path,
100103
endpoint=cors_middleware(
101104
MetadataHandler(metadata).handle,
102105
["GET", "OPTIONS"],

tests/server/auth/test_routes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def test_create_auth_routes_default_paths():
9191

9292

9393
def test_create_auth_routes_custom_base_path():
94-
"""Auth routes are prefixed with the issuer_url path for gateway deployments."""
94+
"""Auth routes are prefixed with the issuer_url path for gateway deployments.
95+
96+
Per RFC 8414 3.1 / RFC 8615 3, the well-known discovery URI is rooted at the
97+
domain and inserted *before* the issuer's path component, not after it.
98+
"""
9599
provider = MockOAuthProvider()
96100
routes = create_auth_routes(
97101
provider,
@@ -100,7 +104,7 @@ def test_create_auth_routes_custom_base_path():
100104
revocation_options=RevocationOptions(enabled=True),
101105
)
102106
paths = [route.path for route in routes]
103-
assert "/custom/path/.well-known/oauth-authorization-server" in paths
107+
assert "/.well-known/oauth-authorization-server/custom/path" in paths
104108
assert "/custom/path/authorize" in paths
105109
assert "/custom/path/token" in paths
106110
assert "/custom/path/register" in paths
@@ -117,6 +121,6 @@ def test_create_auth_routes_trailing_slash_stripped():
117121
revocation_options=RevocationOptions(enabled=True),
118122
)
119123
paths = [route.path for route in routes]
120-
assert "/base/.well-known/oauth-authorization-server" in paths
124+
assert "/.well-known/oauth-authorization-server/base" in paths
121125
assert "/base/authorize" in paths
122126
assert "/base/token" in paths

0 commit comments

Comments
 (0)