File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
exercises/99.finished/99.solution/src Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -102,3 +102,22 @@ export async function handleOAuthProtectedResourceRequest(request: Request) {
102102 scopes_supported : [ 'read' , 'write' ] ,
103103 } )
104104}
105+
106+ /**
107+ * Handles requests for OAuth authorization server metadata.
108+ * Fetches the metadata from the auth server and forwards it to the client.
109+ * This should only be used for backwards compatibility. Newer clients should
110+ * use `/.well-known/oauth-protected-resource/mcp` to discover the authorization
111+ * server and make this request directly to the authorization server instead.
112+ */
113+ export async function handleOAuthAuthorizationServerRequest ( ) {
114+ const metadataUrl = new URL (
115+ '/.well-known/oauth-authorization-server' ,
116+ EPIC_ME_AUTH_SERVER_URL ,
117+ )
118+
119+ const response = await fetch ( metadataUrl . toString ( ) )
120+ const data = await response . json ( )
121+
122+ return Response . json ( data )
123+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 type AuthInfo ,
1111 getAuthInfo ,
1212 handleInsufficientScope ,
13+ handleOAuthAuthorizationServerRequest ,
1314 handleOAuthProtectedResourceRequest ,
1415 handleUnauthorized ,
1516 validateScopes ,
@@ -96,6 +97,11 @@ export default {
9697 return handleOAuthProtectedResourceRequest ( request )
9798 }
9899
100+ // for backwards compatibility with old clients that think we're the authorization server
101+ if ( url . pathname === '/.well-known/oauth-authorization-server' ) {
102+ return handleOAuthAuthorizationServerRequest ( )
103+ }
104+
99105 if ( url . pathname === '/mcp' ) {
100106 const authInfo = await getAuthInfo ( request )
101107 if ( ! authInfo ) return handleUnauthorized ( request )
You can’t perform that action at this time.
0 commit comments