@@ -716,7 +716,7 @@ export function pushedAuthorizationEndpoint(
716716 } )
717717}
718718
719- export function getMetadataEndpoints ( router : Router , issuer : VcIssuer ) {
719+ export function getMetadataEndpoints ( router : Router , issuer : VcIssuer , rootRouter ?: Router , baseUrl ?: URL | string ) {
720720 const credentialIssuerHandler = ( request : Request , response : Response ) => {
721721 return response . json ( issuer . issuerMetadata )
722722 }
@@ -725,36 +725,20 @@ export function getMetadataEndpoints(router: Router, issuer: VcIssuer) {
725725 return response . json ( issuer . authorizationServerMetadata )
726726 }
727727
728- // Original endpoints
728+ // Original endpoints on the context router
729729 router . get ( WellKnownEndpoints . OPENID4VCI_ISSUER , credentialIssuerHandler )
730730 router . get ( WellKnownEndpoints . OAUTH_AS , authorizationServerHandler )
731731
732- // Alternative endpoints with .well-known at root
733- const alternativeCredentialIssuerEndpoint = getAlternativeWellKnownEndpoint ( WellKnownEndpoints . OPENID4VCI_ISSUER )
734- const alternativeAuthServerEndpoint = getAlternativeWellKnownEndpoint ( WellKnownEndpoints . OAUTH_AS )
735-
736- if ( alternativeCredentialIssuerEndpoint ) {
737- router . get ( alternativeCredentialIssuerEndpoint , credentialIssuerHandler )
738- }
739-
740- if ( alternativeAuthServerEndpoint ) {
741- router . get ( alternativeAuthServerEndpoint , authorizationServerHandler )
742- }
743- }
744-
745- function getAlternativeWellKnownEndpoint ( originalEndpoint : string ) : string | null {
746- const wellKnownIndex = originalEndpoint . indexOf ( '/.well-known/' )
747- if ( wellKnownIndex <= 0 ) {
748- return null
732+ // Alternative root-level endpoints if rootRouter provided
733+ if ( rootRouter && baseUrl ) {
734+ const basePath = getBasePath ( baseUrl )
735+ if ( basePath && basePath !== '/' ) {
736+ rootRouter . get ( `/.well-known/openid-credential-issuer${ basePath } ` , credentialIssuerHandler )
737+ rootRouter . get ( `/.well-known/oauth-authorization-server${ basePath } ` , authorizationServerHandler )
738+ }
749739 }
750-
751- const contextPath = originalEndpoint . substring ( 0 , wellKnownIndex )
752- const wellKnownResource = originalEndpoint . substring ( wellKnownIndex + '/.well-known/' . length )
753-
754- return `/.well-known/${ wellKnownResource } ${ contextPath } `
755740}
756741
757-
758742export function determinePath (
759743 baseUrl : URL | string | undefined ,
760744 endpoint : string ,
0 commit comments