Skip to content

feat: add issuer_state to credential request body too #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: wip/verify
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lib/services/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class OpenID4VCIClient implements IOpenID4VCIClient {
authorizationRequestURL.search = authParams.toString();
}

await this.openID4VCIClientStateRepository.create(new OpenID4VCIClientState(userHandleB64u, this.config.credentialIssuerIdentifier, state, code_verifier, credentialConfigurationId))
await this.openID4VCIClientStateRepository.create(new OpenID4VCIClientState(userHandleB64u, this.config.credentialIssuerIdentifier, state, issuer_state, code_verifier, credentialConfigurationId))

const modifiedAuthorizationRequest = await this.authorizationRequestModifier(this.config.credentialIssuerIdentifier, authorizationRequestURL.toString(), request_uri, this.config.clientId);

Expand Down Expand Up @@ -422,6 +422,17 @@ export class OpenID4VCIClient implements IOpenID4VCIClient {
"format": this.config.credentialIssuerMetadata.credential_configurations_supported[flowState.credentialConfigurationId].format,
} as any;

// In order to support any OIDC server, we need to add the issuer state to the body.
// The OIDC4VCI spec doesn't define a standard way to relay the issuer state, many implementations presume it is part of the access token.
// But the spec also requires the access token to be considered "opaque".
// And most OIDC servers won't pass the issuer_state in their access token along - if they have a JWT in the first place!
// The spec allow additional attributes so adding it, should not cause trouble at issuers - they should simply ignore it if they cannot handdle it.
//
// Hence, we duplicate the issuer_state in the body - e.g. the Sphereon agent handles this extra attribute.
if (flowState.issuer_state) {
credentialEndpointBody.issuer_state = flowState.issuer_state;
}

if (this.config.credentialIssuerMetadata?.batch_credential_issuance?.batch_size) {
credentialEndpointBody.proofs = {
jwt: proofsArray
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/OpenID4VCIClientState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class OpenID4VCIClientState {
public userHandleB64U: string,
public credentialIssuerIdentifier: string,
public state: string,
public issuer_state: string | undefined,
public code_verifier: string,
public credentialConfigurationId: string,
public tokenResponse?: {
Expand Down