From b8bb3591ea704a777cfe057920edc8cd61faf3ef Mon Sep 17 00:00:00 2001 From: sksadjad Date: Fri, 17 May 2024 17:01:17 +0200 Subject: [PATCH] fix: changed the logic for pin validation --- packages/client/lib/AccessTokenClient.ts | 2 +- .../client/lib/__tests__/AccessTokenClient.spec.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/client/lib/AccessTokenClient.ts b/packages/client/lib/AccessTokenClient.ts index 46f609c5..68ba7d21 100644 --- a/packages/client/lib/AccessTokenClient.ts +++ b/packages/client/lib/AccessTokenClient.ts @@ -213,7 +213,7 @@ export class AccessTokenClient { if (accessTokenRequest.grant_type === GrantTypes.PRE_AUTHORIZED_CODE) { this.assertPreAuthorizedGrantType(accessTokenRequest.grant_type); this.assertNonEmptyPreAuthorizedCode(accessTokenRequest); - this.assertAlphanumericPin(pinMeta, accessTokenRequest['pre-authorized_code']); + this.assertAlphanumericPin(pinMeta, accessTokenRequest.user_pin); } else if (accessTokenRequest.grant_type === GrantTypes.AUTHORIZATION_CODE) { this.assertAuthorizationGrantType(accessTokenRequest.grant_type); this.assertNonEmptyCodeVerifier(accessTokenRequest); diff --git a/packages/client/lib/__tests__/AccessTokenClient.spec.ts b/packages/client/lib/__tests__/AccessTokenClient.spec.ts index 268ce3d4..34e22660 100644 --- a/packages/client/lib/__tests__/AccessTokenClient.spec.ts +++ b/packages/client/lib/__tests__/AccessTokenClient.spec.ts @@ -28,6 +28,7 @@ describe('AccessTokenClient should', () => { const accessTokenRequest: AccessTokenRequest = { grant_type: GrantTypes.PRE_AUTHORIZED_CODE, + user_pin: '20221013', 'pre-authorized_code': '20221013', client_id: 'sphereon', } as AccessTokenRequest; @@ -219,12 +220,11 @@ describe('AccessTokenClient should', () => { .post(/.*/) .reply(200, {}); - await expect(() => - accessTokenClient.acquireAccessToken({ - credentialOffer: INITIATION_TEST, - pin: '1234', - }), - ).rejects.toThrow(Error('A valid pin must be present according to the specified transaction code requirements.')); + const response: OpenIDResponse = await accessTokenClient.acquireAccessToken({ + credentialOffer: INITIATION_TEST, + pin: '1234', + }) + expect(response.successBody).toBeDefined() }); it('get error if no as, issuer and metadata values are present', async () => {