fix: make VPResponse.VPToken spec-compliant (map[string][]string)#366
Closed
leifj wants to merge 1 commit into
Closed
fix: make VPResponse.VPToken spec-compliant (map[string][]string)#366leifj wants to merge 1 commit into
leifj wants to merge 1 commit into
Conversation
OID4VP 1.0 §8.1 requires vp_token values to be arrays of presentations. The previous map[string]string type caused json.Unmarshal to silently drop array values from spec-compliant wallets, resulting in 'VP Token not found' errors. - Change VPToken from map[string]string to map[string][]string - Update API gateway handler to unwrap first token from array - Update verifier handler with same unwrap logic - Update tests to use new type Fixes SUNET#365
|
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the OpenID4VP direct_post (JWE) response handling to align with OID4VP 1.0 §8.1 by modeling vp_token values as arrays, preventing silent JSON unmarshal drops from spec-compliant wallets.
Changes:
- Change
VPResponse.VPTokenfrommap[string]stringtomap[string][]stringto match the spec’s array-of-presentations requirement. - Update verifier/APIGW handlers to unwrap a token from the array after checking it’s non-empty.
- Adjust the VPResponse marshal/unmarshal test to use the new array type.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/openid4vp/response_parameters.go | Updates VPResponse vp_token type to map values as []string for spec compliance. |
| internal/apigw/apiv1/handlers_verifier.go | Unwraps vp_token array entry when extracting the token for the credential query ID. |
| internal/verifier/apiv1/handlers_verification.go | Unwraps vp_token array entry when extracting the token per scope. |
| pkg/openid4vp/response_parameters_additional_test.go | Updates VPResponse test data to use map[string][]string and validates round-trip. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if !ok { | ||
| vpTokens, ok := vpResponse.VPToken[credQueryID] | ||
| if !ok || len(vpTokens) == 0 { | ||
| c.log.Error(nil, "VP Token not found for credential query", "query_id", credQueryID, "available_keys", vpResponse.VPToken) |
| if !ok || len(vpTokens) == 0 { | ||
| c.log.Error(nil, "VP Token not found for credential query", "query_id", credQueryID, "available_keys", vpResponse.VPToken) | ||
| return nil, fmt.Errorf("VP Token not found for credential query: %s", credQueryID) | ||
| } |
| if !ok || len(vpTokens) == 0 { | ||
| c.log.Error(nil, "VP token not found for scope", "scope", scope) | ||
| return nil, fmt.Errorf("VP token not found for scope: %s", scope) | ||
| } |
Contributor
Author
|
Superceeded by #386 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
VPResponse.VPTokenwas typed asmap[string]string, but the OID4VP 1.0 spec (§8.1) requires eachvp_tokenvalue to be an array of presentations.When a spec-compliant wallet sends
{"vp_token": {"pid_1_5": ["eyJ..."]}},json.Unmarshalsilently drops the entry because it cannot coerce[]stringintostring, leaving the map empty and causing downstream "VP Token not found" errors.Changes
response_parameters.go— ChangedVPTokenfrommap[string]stringtomap[string][]stringhandlers_verifier.go— Updated map lookup to unwrapvpTokens[0]after length checkhandlers_verification.go— Same unwrap logic for the verifier handlerresponse_parameters_additional_test.go— Updated test to use new array typeFixes #365