Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-rabbits-throw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openid4vc/openid4vp": patch
---

fix: allow string for expires_in when parsing openid4vp response payload to account for response submitted as url encoded
Original file line number Diff line number Diff line change
@@ -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: '$',
},
],
},
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof zOpenid4vpAuthorizationResponse>