From 2c06a91607f5976fc6b2d8b6036241fef445e625 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Thu, 3 Jul 2025 17:13:15 +0200 Subject: [PATCH 1/2] docs(changeset): fix: allow string for expires_in when parsing openid4vp response paylaod to account for response submitted as url encoded Signed-off-by: Timo Glastra --- .changeset/pretty-rabbits-throw.md | 5 ++++ ...rse-authorization-response-payload.test.ts | 29 +++++++++++++++++++ .../z-authorization-response.ts | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changeset/pretty-rabbits-throw.md create mode 100644 packages/openid4vp/src/authorization-response/__tests__/parse-authorization-response-payload.test.ts diff --git a/.changeset/pretty-rabbits-throw.md b/.changeset/pretty-rabbits-throw.md new file mode 100644 index 00000000..7ce9ef6b --- /dev/null +++ b/.changeset/pretty-rabbits-throw.md @@ -0,0 +1,5 @@ +--- +"@openid4vc/openid4vp": patch +--- + +fix: allow string for expires_in when parsing openid4vp response paylaod to account for response submitted as url encoded diff --git a/packages/openid4vp/src/authorization-response/__tests__/parse-authorization-response-payload.test.ts b/packages/openid4vp/src/authorization-response/__tests__/parse-authorization-response-payload.test.ts new file mode 100644 index 00000000..731cd627 --- /dev/null +++ b/packages/openid4vp/src/authorization-response/__tests__/parse-authorization-response-payload.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test } from 'vitest' +import { parseOpenid4VpAuthorizationResponsePayload } from '../parse-authorization-response-payload' + +describe('parseOpenid4VpAuthorizationResponsePayload', () => { + test('should correctly handle stringified arguments due to response submitted as query', () => { + const parsedPayload = Object.fromEntries( + new URLSearchParams( + 'expires_in=6000&state=126781532216424167140483&presentation_submission=%7B%22id%22%3A%22-tM_1SXzc0Q5hJrTkb4vV%22%2C%22definition_id%22%3A%22307d67e7-e41b-416a-99da-334858b346b7%22%2C%22descriptor_map%22%3A%5B%7B%22id%22%3A%227379f4ed-4781-455f-b33d-d29f6c90cda2%22%2C%22format%22%3A%22vc%2Bsd-jwt%22%2C%22path%22%3A%22%24%22%7D%5D%7D&vp_token=vptoken' + ).entries() + ) + + expect(parseOpenid4VpAuthorizationResponsePayload(parsedPayload)).toEqual({ + expires_in: 6000, + state: '126781532216424167140483', + vp_token: 'vptoken', + presentation_submission: { + id: '-tM_1SXzc0Q5hJrTkb4vV', + definition_id: '307d67e7-e41b-416a-99da-334858b346b7', + descriptor_map: [ + { + id: '7379f4ed-4781-455f-b33d-d29f6c90cda2', + format: 'vc+sd-jwt', + path: '$', + }, + ], + }, + }) + }) +}) diff --git a/packages/openid4vp/src/authorization-response/z-authorization-response.ts b/packages/openid4vp/src/authorization-response/z-authorization-response.ts index eb0130d4..a02a699d 100644 --- a/packages/openid4vp/src/authorization-response/z-authorization-response.ts +++ b/packages/openid4vp/src/authorization-response/z-authorization-response.ts @@ -12,7 +12,7 @@ export const zOpenid4vpAuthorizationResponse = z refresh_token: z.string().optional(), token_type: z.string().optional(), access_token: z.string().optional(), - expires_in: z.number().optional(), + expires_in: z.coerce.number().optional(), }) .passthrough() export type Openid4vpAuthorizationResponse = z.infer From ce87514ef67dae00c1b4c3f40f6d0834ec5c6bd9 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Thu, 3 Jul 2025 17:21:06 +0200 Subject: [PATCH 2/2] Update .changeset/pretty-rabbits-throw.md Co-authored-by: Henrique Dias Signed-off-by: Timo Glastra --- .changeset/pretty-rabbits-throw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/pretty-rabbits-throw.md b/.changeset/pretty-rabbits-throw.md index 7ce9ef6b..1201552f 100644 --- a/.changeset/pretty-rabbits-throw.md +++ b/.changeset/pretty-rabbits-throw.md @@ -2,4 +2,4 @@ "@openid4vc/openid4vp": patch --- -fix: allow string for expires_in when parsing openid4vp response paylaod to account for response submitted as url encoded +fix: allow string for expires_in when parsing openid4vp response payload to account for response submitted as url encoded