@@ -27,7 +27,7 @@ import {
2727 getCredentialOfferEndpoint ,
2828 getCredentialOfferReferenceEndpoint ,
2929 getIssueStatusEndpoint ,
30- getMetadataEndpoints ,
30+ getMetadataEndpoints , nonceEndpoint ,
3131 pushedAuthorizationEndpoint
3232} from './oid4vci-api-functions'
3333
@@ -38,7 +38,7 @@ function buildVCIFromEnvironment() {
3838 . withFormat ( process . env . credential_supported_format as unknown as OID4VCICredentialFormat )
3939 . withCredentialName ( process . env . credential_supported_name_1 as string )
4040 . withCredentialDefinition ( {
41- type : [ process . env . credential_supported_1_definition_type_1 as string , process . env . credential_supported_1_definition_type_2 as string ] ,
41+ type : [ process . env . credential_supported_1_definition_type_1 as string , process . env . credential_supported_1_definition_type_2 as string ]
4242 // TODO: setup credentialSubject here from env
4343 // credentialSubject
4444 } )
@@ -47,20 +47,24 @@ function buildVCIFromEnvironment() {
4747 locale : process . env . credential_display_locale as string ,
4848 logo : {
4949 url : process . env . credential_display_logo_url as string ,
50- alt_text : process . env . credential_display_logo_alt_text as string ,
50+ alt_text : process . env . credential_display_logo_alt_text as string
5151 } ,
5252 background_color : process . env . credential_display_background_color as string ,
53- text_color : process . env . credential_display_text_color as string ,
53+ text_color : process . env . credential_display_text_color as string
5454 } )
5555 . build ( )
5656 const issuerBuilder = new VcIssuerBuilder ( )
57- . withTXCode ( { length : process . env . user_pin_length as unknown as number , input_mode : process . env . user_pin_input_mode as 'numeric' | 'text' } )
57+ . withTXCode ( {
58+ length : process . env . user_pin_length as unknown as number ,
59+ input_mode : process . env . user_pin_input_mode as 'numeric' | 'text'
60+ } )
5861 . withAuthorizationServers ( process . env . authorization_server as string )
5962 . withCredentialEndpoint ( process . env . credential_endpoint as string )
63+ . withNonceEndpoint ( process . env . nonce_endpoint as string )
6064 . withCredentialIssuer ( process . env . credential_issuer as string )
6165 . withIssuerDisplay ( {
6266 name : process . env . issuer_name as string ,
63- locale : process . env . issuer_locale as string ,
67+ locale : process . env . issuer_locale as string
6468 } )
6569 . withCredentialConfigurationsSupported ( credentialsSupported )
6670 . withInMemoryCredentialOfferState ( )
@@ -73,7 +77,7 @@ function buildVCIFromEnvironment() {
7377 issuerBuilder . withASClientMetadataParams ( {
7478 client_id : process . env . authorization_server_client_id ,
7579 client_secret : process . env . authorization_server_client_secret ,
76- redirect_uris : [ process . env . authorization_server_redirect_uri ] ,
80+ redirect_uris : [ process . env . authorization_server_redirect_uri ]
7781 } )
7882 }
7983
@@ -133,6 +137,11 @@ export interface IOID4VCIEndpointOpts {
133137 getIssuePayloadOpts ?: IGetIssuePayloadEndpointOpts
134138 parOpts ?: ISingleEndpointOpts
135139 authorizationChallengeOpts ?: IAuthorizationChallengeEndpointOpts
140+ nonceOpts ?: INonceEndpointOpts
141+ }
142+
143+ export interface INonceEndpointOpts extends ISingleEndpointOpts {
144+ baseUrl : string | URL
136145}
137146
138147export interface IOID4VCIServerOpts extends HasEndpointOpts {
@@ -153,7 +162,9 @@ export class OID4VCIServer {
153162
154163 constructor (
155164 expressSupport : ExpressSupport ,
156- opts : IOID4VCIServerOpts & { issuer ?: VcIssuer } /*If not supplied as argument, it will be fully configured from environment variables*/ ,
165+ opts : IOID4VCIServerOpts & {
166+ issuer ?: VcIssuer
167+ } /*If not supplied as argument, it will be fully configured from environment variables*/
157168 ) {
158169 this . _baseUrl = new URL ( opts ?. baseUrl ?? process . env . BASE_URL ?? opts ?. issuer ?. issuerMetadata ?. credential_issuer ?? 'http://localhost' )
159170 this . _expressSupport = expressSupport
@@ -169,7 +180,7 @@ export class OID4VCIServer {
169180 if ( this . isGetIssuePayloadEndpointEnabled ( opts ?. endpointOpts ?. getIssuePayloadOpts ) ) {
170181 issuerPayloadPath = getCredentialOfferReferenceEndpoint ( this . router , this . issuer , {
171182 ...opts ?. endpointOpts ?. getIssuePayloadOpts ,
172- baseUrl : this . baseUrl ,
183+ baseUrl : this . baseUrl
173184 } )
174185 }
175186
@@ -185,11 +196,11 @@ export class OID4VCIServer {
185196 opts . endpointOpts ?. tokenEndpointOpts ?. accessTokenVerificationCallback ??
186197 ( this . _asClientOpts
187198 ? oidcAccessTokenVerifyCallback ( {
188- clientMetadata : this . _asClientOpts ,
189- credentialIssuer : this . _issuer . issuerMetadata . credential_issuer ,
190- authorizationServer : this . _issuer . issuerMetadata . authorization_servers ! [ 0 ] ,
191- } )
192- : undefined ) ,
199+ clientMetadata : this . _asClientOpts ,
200+ credentialIssuer : this . _issuer . issuerMetadata . credential_issuer ,
201+ authorizationServer : this . _issuer . issuerMetadata . authorization_servers ! [ 0 ]
202+ } )
203+ : undefined )
193204 } )
194205 this . assertAccessTokenHandling ( )
195206 if ( ! this . isTokenEndpointDisabled ( opts ?. endpointOpts ?. tokenEndpointOpts , opts ?. asClientOpts ) ) {
@@ -204,7 +215,17 @@ export class OID4VCIServer {
204215 } else if ( ! opts ?. endpointOpts ?. authorizationChallengeOpts ?. verifyAuthResponseCallback ) {
205216 throw Error ( `Unable to enable authorization challenge endpoint. No verifyAuthResponseCallback present in authorization challenge options` )
206217 }
207- authorizationChallengeEndpoint ( this . router , this . issuer , { ...opts ?. endpointOpts ?. authorizationChallengeOpts , baseUrl : this . baseUrl } )
218+ authorizationChallengeEndpoint ( this . router , this . issuer , {
219+ ...opts ?. endpointOpts ?. authorizationChallengeOpts ,
220+ baseUrl : this . baseUrl
221+ } )
222+ }
223+
224+ if ( this . isNonceEndpointEnabled ( opts ?. endpointOpts ?. nonceOpts ) ) {
225+ nonceEndpoint ( this . router , this . issuer , {
226+ ...opts ?. endpointOpts ?. nonceOpts ,
227+ baseUrl : this . baseUrl ,
228+ } )
208229 }
209230 this . _app . use ( getBasePath ( this . baseUrl ) , this . _router )
210231 }
@@ -253,7 +274,7 @@ export class OID4VCIServer {
253274 if ( this . isTokenEndpointDisabled ( tokenEndpointOpts , this . issuer . asClientOpts ) ) {
254275 if ( ! authServer || authServer . length === 0 ) {
255276 throw Error (
256- `No Authorization Server (AS) is defined in the issuer metadata and the token endpoint is disabled. An AS or token endpoints needs to be present` ,
277+ `No Authorization Server (AS) is defined in the issuer metadata and the token endpoint is disabled. An AS or token endpoints needs to be present`
257278 )
258279 }
259280 if ( this . issuer . asClientOpts ) {
@@ -264,13 +285,18 @@ export class OID4VCIServer {
264285 } else {
265286 if ( authServer && authServer . some ( ( as ) => as !== this . issuer . issuerMetadata . credential_issuer ) ) {
266287 throw Error (
267- `An external Authorization Server (AS) was already enabled in the issuer metadata (${ authServer } ). Cannot both have an AS and enable the token endpoint at the same time ` ,
288+ `An external Authorization Server (AS) was already enabled in the issuer metadata (${ authServer } ). Cannot both have an AS and enable the token endpoint at the same time `
268289 )
269290 } else if ( this . _asClientOpts ) {
270291 throw Error ( `OIDC Client metadata is set, but the token endpoint is not disabled. This is not supported.` )
271292 }
272293 }
273294 }
295+
296+ private isNonceEndpointEnabled ( nonceEndpointOpts ?: INonceEndpointOpts ) {
297+ return nonceEndpointOpts ?. enabled !== false || process . env . NONCE_ENDPOINT_ENABLED !== 'false'
298+ }
299+
274300 get baseUrl ( ) : URL {
275301 return this . _baseUrl
276302 }
0 commit comments