Skip to content

Commit 7af1d01

Browse files
committed
chore: add draft v1 .well-known endpoints
1 parent aeff575 commit 7af1d01

2 files changed

Lines changed: 21 additions & 27 deletions

File tree

packages/issuer-rest/lib/OID4VCIServer.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,17 @@ export class OID4VCIServer {
175175
opts.asClientOpts || this._issuer.asClientOpts ? ({ ...opts.asClientOpts, ...this._issuer.asClientOpts } as ClientMetadata) : undefined
176176

177177
pushedAuthorizationEndpoint(this.router, this.issuer, this.authRequestsData)
178-
getMetadataEndpoints(this.router, this.issuer)
178+
179+
// Create root router for alternative .well-known endpoints if needed
180+
const basePath = getBasePath(this.baseUrl)
181+
let rootRouter: express.Router | undefined
182+
if (basePath && basePath !== '/') {
183+
rootRouter = express.Router()
184+
this._app.use('/', rootRouter)
185+
}
186+
187+
getMetadataEndpoints(this.router, this.issuer, rootRouter, this.baseUrl)
188+
179189
let issuerPayloadPath: string | undefined
180190
if (this.isGetIssuePayloadEndpointEnabled(opts?.endpointOpts?.getIssuePayloadOpts)) {
181191
issuerPayloadPath = getCredentialOfferReferenceEndpoint(this.router, this.issuer, {
@@ -227,7 +237,7 @@ export class OID4VCIServer {
227237
baseUrl: this.baseUrl,
228238
})
229239
}
230-
this._app.use(getBasePath(this.baseUrl), this._router)
240+
this._app.use(basePath, this._router)
231241
}
232242

233243
public get app(): Express {

packages/issuer-rest/lib/oid4vci-api-functions.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
758742
export function determinePath(
759743
baseUrl: URL | string | undefined,
760744
endpoint: string,

0 commit comments

Comments
 (0)