Skip to content

Commit d993974

Browse files
authored
Merge pull request #208 from Sphereon-Opensource/feature/SSISDK-73_well-known-draftv1
feature/SSISDK-73_well-known-draftv1
2 parents 9cf0d8a + 56f5629 commit d993974

2 files changed

Lines changed: 54 additions & 7 deletions

File tree

packages/issuer-rest/lib/OID4VCIServer.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ export interface INonceEndpointOpts extends ISingleEndpointOpts {
144144
baseUrl: string | URL
145145
}
146146

147+
export enum WellKnownHostLocation {
148+
AT_CONTEXT_PATH = 'AT_CONTEXT_PATH',
149+
AT_ROOT_PATH = 'AT_ROOT_PATH',
150+
AT_BOTH = 'AT_BOTH'
151+
}
152+
147153
export interface IOID4VCIServerOpts extends HasEndpointOpts {
148154
asClientOpts?: ClientMetadata
149155
endpointOpts?: IOID4VCIEndpointOpts
150156
baseUrl?: string
157+
wellKnownHostLocation?: WellKnownHostLocation
151158
}
152159

153160
export class OID4VCIServer {
@@ -159,6 +166,7 @@ export class OID4VCIServer {
159166
// private readonly _server?: http.Server
160167
private readonly _router: express.Router
161168
private readonly _asClientOpts?: ClientMetadata
169+
private readonly _wellknownHostLocation?: WellKnownHostLocation
162170

163171
constructor(
164172
expressSupport: ExpressSupport,
@@ -173,9 +181,23 @@ export class OID4VCIServer {
173181
this._issuer = opts?.issuer ? opts.issuer : buildVCIFromEnvironment()
174182
this._asClientOpts =
175183
opts.asClientOpts || this._issuer.asClientOpts ? ({ ...opts.asClientOpts, ...this._issuer.asClientOpts } as ClientMetadata) : undefined
176-
184+
this._wellknownHostLocation = opts?.wellKnownHostLocation ?? (process.env.WELLKNOWN_HOST_LOCATION as WellKnownHostLocation) ?? WellKnownHostLocation.AT_BOTH
177185
pushedAuthorizationEndpoint(this.router, this.issuer, this.authRequestsData)
178-
getMetadataEndpoints(this.router, this.issuer)
186+
187+
// Create root router for alternative .well-known endpoints if needed
188+
const basePath = getBasePath(this.baseUrl)
189+
let rootRouter: express.Router | undefined
190+
if (basePath && basePath !== '/' && (this.wellknownHostLocation == WellKnownHostLocation.AT_ROOT_PATH || this.wellknownHostLocation == WellKnownHostLocation.AT_BOTH)) {
191+
rootRouter = express.Router()
192+
this._app.use('/', rootRouter)
193+
}
194+
195+
getMetadataEndpoints(this.router, this.issuer, {
196+
rootRouter,
197+
basePath,
198+
wellKnownHostLocation: this.wellknownHostLocation
199+
})
200+
179201
let issuerPayloadPath: string | undefined
180202
if (this.isGetIssuePayloadEndpointEnabled(opts?.endpointOpts?.getIssuePayloadOpts)) {
181203
issuerPayloadPath = getCredentialOfferReferenceEndpoint(this.router, this.issuer, {
@@ -227,7 +249,7 @@ export class OID4VCIServer {
227249
baseUrl: this.baseUrl,
228250
})
229251
}
230-
this._app.use(getBasePath(this.baseUrl), this._router)
252+
this._app.use(basePath, this._router)
231253
}
232254

233255
public get app(): Express {
@@ -300,4 +322,8 @@ export class OID4VCIServer {
300322
get baseUrl(): URL {
301323
return this._baseUrl
302324
}
325+
326+
get wellknownHostLocation(): WellKnownHostLocation | undefined {
327+
return this._wellknownHostLocation
328+
}
303329
}

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
ICreateCredentialOfferURIResponse,
4242
IGetCredentialOfferEndpointOpts,
4343
IGetIssueStatusEndpointOpts,
44-
INonceEndpointOpts
44+
INonceEndpointOpts, WellKnownHostLocation
4545
} from './OID4VCIServer'
4646
import { validateRequestBody } from './expressUtils'
4747

@@ -716,16 +716,37 @@ export function pushedAuthorizationEndpoint(
716716
})
717717
}
718718

719-
export function getMetadataEndpoints(router: Router, issuer: VcIssuer) {
719+
export function getMetadataEndpoints(
720+
router: Router,
721+
issuer: VcIssuer,
722+
opts?: {
723+
rootRouter?: Router
724+
basePath?: string
725+
wellKnownHostLocation?: WellKnownHostLocation
726+
}
727+
) {
720728
const credentialIssuerHandler = (request: Request, response: Response) => {
721729
return response.json(issuer.issuerMetadata)
722730
}
723-
router.get(WellKnownEndpoints.OPENID4VCI_ISSUER, credentialIssuerHandler)
724731

725732
const authorizationServerHandler = (request: Request, response: Response) => {
726733
return response.json(issuer.authorizationServerMetadata)
727734
}
728-
router.get(WellKnownEndpoints.OAUTH_AS, authorizationServerHandler)
735+
736+
const location = opts?.wellKnownHostLocation ?? WellKnownHostLocation.AT_BOTH
737+
738+
// Register endpoints on context router if configured
739+
if (location === WellKnownHostLocation.AT_CONTEXT_PATH || location === WellKnownHostLocation.AT_BOTH) {
740+
router.get(WellKnownEndpoints.OPENID4VCI_ISSUER, credentialIssuerHandler)
741+
router.get(WellKnownEndpoints.OAUTH_AS, authorizationServerHandler)
742+
}
743+
744+
// Register endpoints on root router if configured
745+
if (opts?.rootRouter && opts?.basePath && opts.basePath !== '/' &&
746+
(location === WellKnownHostLocation.AT_ROOT_PATH || location === WellKnownHostLocation.AT_BOTH)) {
747+
opts.rootRouter.get(`/.well-known/openid-credential-issuer${opts.basePath}`, credentialIssuerHandler)
748+
opts.rootRouter.get(`/.well-known/oauth-authorization-server${opts.basePath}`, authorizationServerHandler)
749+
}
729750
}
730751

731752
export function determinePath(

0 commit comments

Comments
 (0)