Skip to content

Commit 2c06a91

Browse files
committed
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 <timo@animo.id>
1 parent 213f11d commit 2c06a91

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

.changeset/pretty-rabbits-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@openid4vc/openid4vp": patch
3+
---
4+
5+
fix: allow string for expires_in when parsing openid4vp response paylaod to account for response submitted as url encoded
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { parseOpenid4VpAuthorizationResponsePayload } from '../parse-authorization-response-payload'
3+
4+
describe('parseOpenid4VpAuthorizationResponsePayload', () => {
5+
test('should correctly handle stringified arguments due to response submitted as query', () => {
6+
const parsedPayload = Object.fromEntries(
7+
new URLSearchParams(
8+
'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'
9+
).entries()
10+
)
11+
12+
expect(parseOpenid4VpAuthorizationResponsePayload(parsedPayload)).toEqual({
13+
expires_in: 6000,
14+
state: '126781532216424167140483',
15+
vp_token: 'vptoken',
16+
presentation_submission: {
17+
id: '-tM_1SXzc0Q5hJrTkb4vV',
18+
definition_id: '307d67e7-e41b-416a-99da-334858b346b7',
19+
descriptor_map: [
20+
{
21+
id: '7379f4ed-4781-455f-b33d-d29f6c90cda2',
22+
format: 'vc+sd-jwt',
23+
path: '$',
24+
},
25+
],
26+
},
27+
})
28+
})
29+
})

packages/openid4vp/src/authorization-response/z-authorization-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const zOpenid4vpAuthorizationResponse = z
1212
refresh_token: z.string().optional(),
1313
token_type: z.string().optional(),
1414
access_token: z.string().optional(),
15-
expires_in: z.number().optional(),
15+
expires_in: z.coerce.number().optional(),
1616
})
1717
.passthrough()
1818
export type Openid4vpAuthorizationResponse = z.infer<typeof zOpenid4vpAuthorizationResponse>

0 commit comments

Comments
 (0)