@@ -64,11 +64,11 @@ def _url_from_path(*parts: str) -> str:
6464
6565
6666def _setup_mcp_oauth (app : Dash , mcp_path : str , mcp_authorization_server : str ) -> None :
67- """Register OAuth metadata endpoint and auth gate for MCP.
67+ """Register RFC 9728 Protected Resource Metadata endpoint for MCP.
6868
69- Serves RFC 9728 Protected Resource Metadata so MCP clients can
70- discover the authorization server, and returns 401 with
71- WWW-Authenticate for unauthenticated requests to the MCP endpoint .
69+ Serves discovery metadata so MCP clients can find the authorization
70+ server. Auth enforcement is the responsibility of the hosting platform
71+ (e.g. Plotly Cloud gateway, Dash Embedded, or a reverse proxy) .
7272 """
7373 well_known_path = urljoin ("/.well-known/oauth-protected-resource/" , mcp_path )
7474
@@ -89,26 +89,10 @@ def _serve_resource_metadata() -> Response:
8989 # pylint: disable-next=protected-access
9090 app ._add_url (well_known_path .lstrip ("/" ), _serve_resource_metadata )
9191
92- @app .server .before_request
93- def _mcp_require_auth ():
94- if request .path != app .config .routes_pathname_prefix + mcp_path :
95- return None
96- auth_header = request .headers .get ("Authorization" , "" )
97- if auth_header .startswith ("Bearer " ):
98- return None
99- resource_metadata_url = _url_from_path (well_known_path )
100- return Response (
101- json .dumps ({"error" : "unauthorized" }),
102- status = 401 ,
103- content_type = "application/json" ,
104- headers = {
105- "WWW-Authenticate" : (
106- f'Bearer resource_metadata="{ resource_metadata_url } "'
107- ),
108- },
109- )
110-
111- logger .info ("MCP OAuth enabled, authorization server: %s" , mcp_authorization_server )
92+ logger .info (
93+ "MCP OAuth discovery enabled, authorization server: %s" ,
94+ mcp_authorization_server ,
95+ )
11296
11397
11498def enable_mcp_server (
0 commit comments