@@ -471,7 +471,7 @@ function shouldAttemptFallback(response: Response | undefined, pathname: string)
471471async function discoverMetadataWithFallback (
472472 serverUrl : string | URL ,
473473 wellKnownType : 'oauth-authorization-server' | 'oauth-protected-resource' ,
474- opts ?: { protocolVersion ?: string ; metadataUrl ?: string | URL } ,
474+ opts ?: { protocolVersion ?: string ; metadataUrl ?: string | URL , metadataServerUrl ?: string | URL } ,
475475) : Promise < Response | undefined > {
476476 const issuer = new URL ( serverUrl ) ;
477477 const protocolVersion = opts ?. protocolVersion ?? LATEST_PROTOCOL_VERSION ;
@@ -482,7 +482,7 @@ async function discoverMetadataWithFallback(
482482 } else {
483483 // Try path-aware discovery first
484484 const wellKnownPath = buildWellKnownPath ( wellKnownType , issuer . pathname ) ;
485- url = new URL ( wellKnownPath , issuer ) ;
485+ url = new URL ( wellKnownPath , opts ?. metadataServerUrl ?? issuer ) ;
486486 url . search = issuer . search ;
487487 }
488488
@@ -525,9 +525,13 @@ export async function discoverOAuthMetadata(
525525 protocolVersion ??= LATEST_PROTOCOL_VERSION ;
526526
527527 const response = await discoverMetadataWithFallback (
528- authorizationServerUrl ,
528+ issuer ,
529+ // authorizationServerUrl,
529530 'oauth-authorization-server' ,
530- { protocolVersion} ,
531+ {
532+ protocolVersion,
533+ metadataServerUrl : authorizationServerUrl ,
534+ } ,
531535 ) ;
532536
533537 if ( ! response || response . status === 404 ) {
0 commit comments