Skip to content

Commit

Permalink
chore: client assertion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jun 28, 2024
1 parent c1e1b4a commit ce05539
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ export class AccessTokenClient {
code,
redirectUri,
pin,
pinMetadata,
credentialIssuer: issuer,
metadata,
additionalParams: opts.additionalParams,
pinMetadata,
}),
pinMetadata,
metadata,
Expand Down Expand Up @@ -96,7 +98,7 @@ export class AccessTokenClient {
if (asOpts?.clientOpts?.clientId) {
request.client_id = asOpts.clientOpts.clientId;
}
const credentialIssuer = opts.credentialIssuer ?? credentialOfferRequest?.credential_offer?.credential_issuer;
const credentialIssuer = opts.credentialIssuer ?? credentialOfferRequest?.credential_offer?.credential_issuer ?? opts.metadata?.issuer;
await createJwtBearerClientAssertion(request, { ...opts, credentialIssuer });

if (credentialOfferRequest?.supportedFlows.includes(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/client/lib/AccessTokenClientV1_0_11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class AccessTokenClientV1_0_11 {
code,
redirectUri,
pin,
credentialIssuer: issuer,
metadata,
additionalParams: opts.additionalParams,
pinMetadata: opts.pinMetadata,
}),
isPinRequired,
metadata,
Expand Down Expand Up @@ -95,7 +99,7 @@ export class AccessTokenClientV1_0_11 {
? await toUniformCredentialOfferRequest(opts.credentialOffer as CredentialOfferV1_0_11 | CredentialOfferV1_0_13)
: undefined;
const request: Partial<AccessTokenRequest> = { ...opts.additionalParams };
const credentialIssuer = opts.credentialIssuer ?? credentialOfferRequest?.credential_offer?.credential_issuer;
const credentialIssuer = opts.credentialIssuer ?? credentialOfferRequest?.credential_offer?.credential_issuer ?? opts.metadata?.issuer;

if (asOpts?.clientOpts?.clientId) {
request.client_id = asOpts.clientOpts.clientId;
Expand Down
3 changes: 2 additions & 1 deletion packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class OpenID4VCIClient {
pkce: { disabled: false, codeChallengeMethod: CodeChallengeMethod.S256, ...pkce },
authorizationRequestOpts,
authorizationCodeResponse,
accessToken,
jwk,
endpointMetadata: endpointMetadata?.credentialIssuerMetadata?.authorization_server
? (endpointMetadata as EndpointMetadataResultV1_0_11)
Expand Down Expand Up @@ -295,7 +296,7 @@ export class OpenID4VCIClient {
const kid = asOpts.clientOpts?.kid ?? this._state.kid ?? this._state.authorizationRequestOpts?.requestObjectOpts?.kid;
const clientAssertionType =
asOpts.clientOpts?.clientAssertionType ??
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks === 'function'
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks?.signCallback === 'function'
? 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
: undefined);
if (this.isEBSI() || (clientId && kid)) {
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/OpenID4VCIClientV1_0_11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ export class OpenID4VCIClientV1_0_11 {
authorizationResponse?: string | AuthorizationResponse; // Pass in an auth response, either as URI/redirect, or object
code?: string; // Directly pass in a code from an auth response
redirectUri?: string;
additionalRequestParams?: Record<string, any>;
asOpts?: AuthorizationServerOpts;
}): Promise<AccessTokenResponse> {
const { pin, clientId } = opts ?? {};
const { pin, clientId = this._state.clientId ?? this._state.authorizationRequestOpts?.clientId } = opts ?? {};
let { redirectUri } = opts ?? {};
if (opts?.authorizationResponse) {
this._state.authorizationCodeResponse = { ...toAuthorizationResponsePayload(opts.authorizationResponse) };
Expand Down Expand Up @@ -294,7 +295,7 @@ export class OpenID4VCIClientV1_0_11 {
const kid = asOpts.clientOpts?.kid ?? this._state.kid ?? this._state.authorizationRequestOpts?.requestObjectOpts?.kid;
const clientAssertionType =
asOpts.clientOpts?.clientAssertionType ??
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks === 'function'
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks?.signCallback === 'function'
? 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
: undefined);
if (this.isEBSI() || (clientId && kid)) {
Expand All @@ -319,6 +320,7 @@ export class OpenID4VCIClientV1_0_11 {
code,
redirectUri,
asOpts,
...(opts?.additionalRequestParams && { additionalParams: opts.additionalRequestParams }),
});

if (response.errorBody) {
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/OpenID4VCIClientV1_0_13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ export class OpenID4VCIClientV1_0_13 {
authorizationResponse?: string | AuthorizationResponse; // Pass in an auth response, either as URI/redirect, or object
code?: string; // Directly pass in a code from an auth response
redirectUri?: string;
additionalRequestParams?: Record<string, any>;
asOpts?: AuthorizationServerOpts;
}): Promise<AccessTokenResponse> {
const { pin, clientId } = opts ?? {};
const { pin, clientId = this._state.clientId ?? this._state.authorizationRequestOpts?.clientId } = opts ?? {};
let { redirectUri } = opts ?? {};
if (opts?.authorizationResponse) {
this._state.authorizationCodeResponse = { ...toAuthorizationResponsePayload(opts.authorizationResponse) };
Expand All @@ -284,7 +285,7 @@ export class OpenID4VCIClientV1_0_13 {
const kid = asOpts.clientOpts?.kid ?? this._state.kid ?? this._state.authorizationRequestOpts?.requestObjectOpts?.kid;
const clientAssertionType =
asOpts.clientOpts?.clientAssertionType ??
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks === 'function'
(kid && clientId && typeof asOpts.clientOpts?.signCallbacks?.signCallback === 'function'
? 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
: undefined);
if (this.isEBSI() || (clientId && kid)) {
Expand Down Expand Up @@ -323,6 +324,7 @@ export class OpenID4VCIClientV1_0_13 {
code,
redirectUri,
asOpts,
...(opts?.additionalRequestParams && { additionalParams: opts.additionalRequestParams }),
});

if (response.errorBody) {
Expand Down

0 comments on commit ce05539

Please sign in to comment.