Skip to content

Commit

Permalink
chore: fix clientId from offer
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jan 24, 2024
1 parent 7fc47c5 commit e417ac4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CredentialOfferRequestWithBaseUrl,
CredentialResponse,
CredentialSupported,
EndpointMetadataResult,
EndpointMetadataResult, getClientIdFromCredentialOfferPayload,
getIssuerFromCredentialOfferPayload,
getSupportedCredentials,
getTypesFromCredentialSupported,
Expand All @@ -17,8 +17,8 @@ import {
OID4VCICredentialFormat,
OpenId4VCIVersion,
PKCEOpts,
ProofOfPossessionCallbacks,
} from '@sphereon/oid4vci-common';
ProofOfPossessionCallbacks
} from '@sphereon/oid4vci-common'
import { CredentialFormat } from '@sphereon/ssi-types';
import Debug from 'debug';

Expand Down Expand Up @@ -71,7 +71,7 @@ export class OpenID4VCIClient {
this._credentialIssuer = issuer;
this._kid = kid;
this._alg = alg;
this._clientId = clientId;
this._clientId = clientId ?? (credentialOffer ? getClientIdFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
this._pkce = { ...this._pkce, ...pkce };
this._authorizationRequestOpts = authorizationRequest;
this.syncAuthorizationRequestOpts(authorizationRequest);
Expand Down Expand Up @@ -519,7 +519,11 @@ export class OpenID4VCIClient {

private syncAuthorizationRequestOpts(opts?: AuthorizationRequestOpts) {
if (!this._authorizationRequestOpts && !opts) {
return;
if (this.clientId) {
this._authorizationRequestOpts = { clientId: this.clientId } as AuthorizationRequestOpts
} else {
throw Error('No authorization request options present. Need at least a clientId and redirectUri')
}
}
const authorizationRequestOpts = { ...this._authorizationRequestOpts, ...opts } as AuthorizationRequestOpts;
if (authorizationRequestOpts.clientId) {
Expand Down

0 comments on commit e417ac4

Please sign in to comment.