Skip to content

Commit

Permalink
fix: Do not sort credential types, as issuers might rely on their order
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 7, 2024
1 parent 2bc039c commit 59fba74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getIssuerFromCredentialOfferPayload,
GrantTypes,
IssuerOpts,
JsonURIMode,
OpenIDResponse,
PRE_AUTH_CODE_LITERAL,
TokenErrorResponse,
Expand Down Expand Up @@ -191,7 +192,7 @@ export class AccessTokenClient {
}

private async sendAuthCode(requestTokenURL: string, accessTokenRequest: AccessTokenRequest): Promise<OpenIDResponse<AccessTokenResponse>> {
return await formPost(requestTokenURL, convertJsonToURI(accessTokenRequest));
return await formPost(requestTokenURL, convertJsonToURI(accessTokenRequest, { mode: JsonURIMode.X_FORM_WWW_URLENCODED }));
}

public static determineTokenURL({
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ export class OpenID4VCIClient {
requestBuilder.withDeferredCredentialAwait(deferredCredentialAwait ?? false, deferredCredentialIntervalInMS);
if (this.endpointMetadata?.credentialIssuerMetadata) {
const metadata = this.endpointMetadata.credentialIssuerMetadata;
const types = Array.isArray(credentialTypes) ? [...credentialTypes].sort() : [credentialTypes];
const types = Array.isArray(credentialTypes) ? credentialTypes : [credentialTypes];

if (metadata.credentials_supported && Array.isArray(metadata.credentials_supported)) {
let typeSupported = false;

metadata.credentials_supported.forEach((supportedCredential) => {
const subTypes = getTypesFromCredentialSupported(supportedCredential);
if (
subTypes.sort().every((t, i) => types[i] === t) ||
subTypes.every((t, i) => types[i] === t) ||
(types.length === 1 && (types[0] === supportedCredential.id || subTypes.includes(types[0])))
) {
typeSupported = true;
Expand Down

0 comments on commit 59fba74

Please sign in to comment.