Skip to content

Commit e6222ff

Browse files
committed
feat: Pass in issuer_state to regular state in auth code flow, so we get a better integration with any external OIDC solution
1 parent 4b09936 commit e6222ff

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

packages/client/lib/AuthorizationCodeClient.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export async function createSignedAuthRequestWhenNeeded(requestObject: Record<st
7373
requestObject['request'] = pop.jwt;
7474
}
7575
}
76+
7677
function filterSupportedCredentials(
7778
credentialOffer: CredentialOfferPayloadV1_0_13,
7879
credentialsSupported?: Record<string, CredentialConfigurationSupportedV1_0_13>,
@@ -200,19 +201,28 @@ export const createAuthorizationRequestUrl = async ({
200201
authorization_details: JSON.stringify(handleAuthorizationDetails(endpointMetadata, authorizationDetails)),
201202
...(redirectUri && { redirect_uri: redirectUri }),
202203
...(client_id && { client_id }),
203-
...(credentialOffer?.issuerState && { issuer_state: credentialOffer.issuerState }),
204+
205+
...(credentialOffer?.issuerState && {
206+
issuer_state: credentialOffer.issuerState,
207+
}),
204208
scope: authorizationRequest.scope,
205209
};
206210

211+
if (credentialOffer?.issuerState) {
212+
/* We also pass it in as state, as this would allow an external AS without integration to return it back to the wallet */
213+
queryObj.state = credentialOffer?.issuerState;
214+
}
215+
207216
if (!parEndpoint && parMode === PARMode.REQUIRE) {
208217
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`);
209218
} else if (parEndpoint && parMode !== PARMode.NEVER) {
210219
debug(`USING PAR with endpoint ${parEndpoint}`);
220+
211221
const parResponse = await formPost<PushedAuthorizationResponse>(
212222
parEndpoint,
213223
convertJsonToURI(queryObj, {
214224
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
215-
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
225+
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state', 'state'],
216226
}),
217227
{ contentType: 'application/x-www-form-urlencoded', accept: 'application/json' },
218228
);
@@ -232,7 +242,7 @@ export const createAuthorizationRequestUrl = async ({
232242
debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2));
233243
const url = convertJsonToURI(queryObj, {
234244
baseUrl: endpointMetadata.authorization_endpoint,
235-
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
245+
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state', 'state'],
236246
// arrayTypeProperties: ['authorization_details'],
237247
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
238248
// We do not add the version here, as this always needs to be form encoded

packages/issuer-rest/lib/OID4VCIServer.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import {
88
OID4VCICredentialFormat,
99
QRCodeOpts,
1010
} from '@sphereon/oid4vci-common'
11-
import { CredentialSupportedBuilderV1_13, ITokenEndpointOpts, oidcAccessTokenVerifyCallback, VcIssuer, VcIssuerBuilder } from '@sphereon/oid4vci-issuer'
11+
import {
12+
CredentialSupportedBuilderV1_13,
13+
ITokenEndpointOpts,
14+
oidcAccessTokenVerifyCallback,
15+
VcIssuer,
16+
VcIssuerBuilder,
17+
} from '@sphereon/oid4vci-issuer'
1218
import { ExpressSupport, HasEndpointOpts, ISingleEndpointOpts } from '@sphereon/ssi-express-support'
1319
import express, { Express } from 'express'
1420

@@ -179,7 +185,19 @@ export class OID4VCIServer {
179185
deleteCredentialOfferEndpoint(this.router, this.issuer, opts?.endpointOpts?.deleteCredentialOfferOpts)
180186
}
181187
getCredentialOfferEndpoint(this.router, this.issuer, opts?.endpointOpts?.getCredentialOfferOpts)
182-
getCredentialEndpoint(this.router, this.issuer, { ...opts?.endpointOpts?.tokenEndpointOpts, baseUrl: this.baseUrl, accessTokenVerificationCallback: opts.endpointOpts?.tokenEndpointOpts?.accessTokenVerificationCallback ?? (this._asClientOpts ? oidcAccessTokenVerifyCallback({clientMetadata: this._asClientOpts, credentialIssuer: this._issuer.issuerMetadata.credential_issuer, authorizationServer: this._issuer.issuerMetadata.authorization_servers![0]}) : undefined)})
188+
getCredentialEndpoint(this.router, this.issuer, {
189+
...opts?.endpointOpts?.tokenEndpointOpts,
190+
baseUrl: this.baseUrl,
191+
accessTokenVerificationCallback:
192+
opts.endpointOpts?.tokenEndpointOpts?.accessTokenVerificationCallback ??
193+
(this._asClientOpts
194+
? oidcAccessTokenVerifyCallback({
195+
clientMetadata: this._asClientOpts,
196+
credentialIssuer: this._issuer.issuerMetadata.credential_issuer,
197+
authorizationServer: this._issuer.issuerMetadata.authorization_servers![0],
198+
})
199+
: undefined),
200+
})
183201
this.assertAccessTokenHandling()
184202
if (!this.isTokenEndpointDisabled(opts?.endpointOpts?.tokenEndpointOpts, opts?.asClientOpts)) {
185203
accessTokenEndpoint(this.router, this.issuer, { ...opts?.endpointOpts?.tokenEndpointOpts, baseUrl: this.baseUrl })

packages/issuer/lib/VcIssuer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,14 @@ export class VcIssuer {
180180
statusListOpts?: Array<StatusListOpts>
181181
sessionLifeTimeInSec?: number
182182
}): Promise<CreateCredentialOfferURIResult> {
183-
const { offerMode = 'VALUE', correlationId = shortUUID.generate(), credential_configuration_ids, statusListOpts, credentialOfferUri, redirectUri } = opts
183+
const {
184+
offerMode = 'VALUE',
185+
correlationId = shortUUID.generate(),
186+
credential_configuration_ids,
187+
statusListOpts,
188+
credentialOfferUri,
189+
redirectUri,
190+
} = opts
184191
if (offerMode === 'REFERENCE' && !credentialOfferUri) {
185192
return Promise.reject(Error('credentialOfferUri must be supplied for offerMode REFERENCE!'))
186193
}

0 commit comments

Comments
 (0)