Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require DiscoveryRegistrationCredential in PEX #3484

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
12 changes: 0 additions & 12 deletions discovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,6 @@ func (r *defaultClientRegistrationManager) findCredentialsAndBuildPresentation(c
return nil, fmt.Errorf(errStr, service.ID, subjectDID, err)
}

// add registration params as credential if not already done so by the Presentation Definition
var found bool
for _, cred := range matchingCredentials {
if cred.ID == registrationCredential.ID {
found = true
break
}
}
if !found {
matchingCredentials = append(matchingCredentials, credential.AutoCorrectSelfAttestedCredential(registrationCredential, subjectDID))
}

return r.buildPresentation(ctx, subjectDID, service, matchingCredentials, nil)
}

Expand Down
3 changes: 1 addition & 2 deletions discovery/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ func Test_defaultClientRegistrationManager_activate(t *testing.T) {
ctx.didResolver.EXPECT().Resolve(aliceDID, gomock.Any()).Return(nil, nil, nil)
ctx.wallet.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil)
ctx.wallet.EXPECT().BuildPresentation(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), false).DoAndReturn(func(_ interface{}, credentials []vc.VerifiableCredential, _ interface{}, _ interface{}, _ interface{}) (*vc.VerifiablePresentation, error) {
// expect registration credential
assert.Len(t, credentials, 1)
assert.Len(t, credentials, 0)
return &vpAlice, nil
})
ctx.subjectManager.EXPECT().ListDIDs(gomock.Any(), aliceSubject).Return([]did.DID{aliceDID}, nil)
Expand Down
20 changes: 0 additions & 20 deletions discovery/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,6 @@ func (m *Module) validateRegistration(definition ServiceDefinition, presentation
return fmt.Errorf("verifiable presentation doesn't match required presentation definition: %w", err)
}
if len(creds) != len(presentation.VerifiableCredential) {
// it could be the case that the VP contains a registration credential and the matching credentials do not.
// only return errPresentationDoesNotFulfillDefinition if both contain the registration credential or neither do.
vpContainsRegistrationCredential := false
for _, cred := range presentation.VerifiableCredential {
if slices.Contains(cred.Type, credential.DiscoveryRegistrationCredentialTypeV1URI()) {
vpContainsRegistrationCredential = true
break
}
}
matchingContainsRegistrationCredential := false
for _, cred := range creds {
if slices.Contains(cred.Type, credential.DiscoveryRegistrationCredentialTypeV1URI()) {
matchingContainsRegistrationCredential = true
break
}
}
if vpContainsRegistrationCredential && !matchingContainsRegistrationCredential && len(presentation.VerifiableCredential)-len(creds) == 1 {
return nil
}

return errPresentationDoesNotFulfillDefinition
}
return nil
Expand Down
1 change: 1 addition & 0 deletions discovery/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ func TestModule_Search(t *testing.T) {
{
Presentation: vpAlice,
Fields: map[string]interface{}{
"auth_server_url":"https://example.com/oauth2/alice",
"issuer_field": authorityDID,
},
Parameters: defaultRegistrationParams(aliceSubject),
Expand Down
10 changes: 10 additions & 0 deletions discovery/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ func testDefinitions() map[string]ServiceDefinition {
},
},
},
}, {
Id: "2",
Constraints: &pe.Constraints{
Fields: []pe.Field{
{
Id: to.Ptr("auth_server_url"),
Path: []string{"$.credentialSubject.authServerURL"},
},
},
},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions docs/pages/deployment/discovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Optionally, a POST body can be provided with registration parameters, e.g.:

This can be used to provide additional information. All registration parameters are returned by the search API.
The ``authServerURL`` is added automatically by the Nuts node. It's constructed as ``https://<config.url>/oauth2/<subject_id>``.
Registration parameters can only be used if the specific parameters and/or ``DiscoveryRegistrationCredential`` are required by the Presentation Definition.

Once registered, future refreshes will be done automatically by the Nuts node. These refreshes could fail because of various reasons.
You can check the status of the refreshes by querying the service, e.g.:
Expand Down Expand Up @@ -156,6 +157,18 @@ Service definitions
}
]
}
}, {
"id": "DiscoveryRegistrationCredential",
"constraints": {
"fields": [
{
"id": "auth_server_url",
"path": [
"$.credentialSubject.authServerURL"
]
}
]
}
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions e2e-tests/discovery/definitions/definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
}
]
}
},{
"id": "DiscoveryRegistrationCredential",
"constraints": {
"fields": [
{
"id": "auth_server_url",
"path": [
"$.credentialSubject.authServerURL"
]
}
]
}
}
]
}
Expand Down
Loading