@@ -261,7 +261,9 @@ export async function discoverOAuthProtectedResourceMetadata(
261
261
if ( opts ?. resourceMetadataUrl ) {
262
262
url = new URL ( opts ?. resourceMetadataUrl ) ;
263
263
} else {
264
- url = new URL ( "/.well-known/oauth-protected-resource" , serverUrl ) ;
264
+ const issuer = new URL ( serverUrl ) ;
265
+ const wellKnownPath = buildWellKnownPath ( 'oauth-protected-resource' , issuer . pathname ) ;
266
+ url = new URL ( wellKnownPath , issuer ) ;
265
267
}
266
268
267
269
let response : Response ;
@@ -318,8 +320,8 @@ async function fetchWithCorsRetry(
318
320
/**
319
321
* Constructs the well-known path for OAuth metadata discovery
320
322
*/
321
- function buildWellKnownPath ( pathname : string ) : string {
322
- let wellKnownPath = `/.well-known/oauth-authorization-server ${ pathname } ` ;
323
+ function buildWellKnownPath ( wellKnownPath : string , pathname : string ) : string {
324
+ let wellKnownPath = `/.well-known/${ wellKnownPath } ${ pathname } ` ;
323
325
if ( pathname . endsWith ( '/' ) ) {
324
326
// Strip trailing slash from pathname to avoid double slashes
325
327
wellKnownPath = wellKnownPath . slice ( 0 , - 1 ) ;
@@ -361,7 +363,7 @@ export async function discoverOAuthMetadata(
361
363
const protocolVersion = opts ?. protocolVersion ?? LATEST_PROTOCOL_VERSION ;
362
364
363
365
// Try path-aware discovery first (RFC 8414 compliant)
364
- const wellKnownPath = buildWellKnownPath ( issuer . pathname ) ;
366
+ const wellKnownPath = buildWellKnownPath ( 'oauth-authorization-server' , issuer . pathname ) ;
365
367
const pathAwareUrl = new URL ( wellKnownPath , issuer ) ;
366
368
let response = await tryMetadataDiscovery ( pathAwareUrl , protocolVersion ) ;
367
369
0 commit comments