Skip to content

Commit e9f86ee

Browse files
require DiscoveryRegistrationCredential in PEX (#3484)
1 parent 7f2e6dd commit e9f86ee

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

discovery/client.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,6 @@ func (r *defaultClientRegistrationManager) findCredentialsAndBuildPresentation(c
263263
return nil, fmt.Errorf(errStr, service.ID, subjectDID, err)
264264
}
265265

266-
// add registration params as credential if not already done so by the Presentation Definition
267-
var found bool
268-
for _, cred := range matchingCredentials {
269-
if cred.ID == registrationCredential.ID {
270-
found = true
271-
break
272-
}
273-
}
274-
if !found {
275-
matchingCredentials = append(matchingCredentials, credential.AutoCorrectSelfAttestedCredential(registrationCredential, subjectDID))
276-
}
277-
278266
return r.buildPresentation(ctx, subjectDID, service, matchingCredentials, nil)
279267
}
280268

discovery/client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ func Test_defaultClientRegistrationManager_activate(t *testing.T) {
178178
ctx.didResolver.EXPECT().Resolve(aliceDID, gomock.Any()).Return(nil, nil, nil)
179179
ctx.wallet.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil)
180180
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) {
181-
// expect registration credential
182-
assert.Len(t, credentials, 1)
181+
assert.Len(t, credentials, 0)
183182
return &vpAlice, nil
184183
})
185184
ctx.subjectManager.EXPECT().ListDIDs(gomock.Any(), aliceSubject).Return([]did.DID{aliceDID}, nil)

discovery/module.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,26 +289,6 @@ func (m *Module) validateRegistration(definition ServiceDefinition, presentation
289289
return fmt.Errorf("verifiable presentation doesn't match required presentation definition: %w", err)
290290
}
291291
if len(creds) != len(presentation.VerifiableCredential) {
292-
// it could be the case that the VP contains a registration credential and the matching credentials do not.
293-
// only return errPresentationDoesNotFulfillDefinition if both contain the registration credential or neither do.
294-
vpContainsRegistrationCredential := false
295-
for _, cred := range presentation.VerifiableCredential {
296-
if slices.Contains(cred.Type, credential.DiscoveryRegistrationCredentialTypeV1URI()) {
297-
vpContainsRegistrationCredential = true
298-
break
299-
}
300-
}
301-
matchingContainsRegistrationCredential := false
302-
for _, cred := range creds {
303-
if slices.Contains(cred.Type, credential.DiscoveryRegistrationCredentialTypeV1URI()) {
304-
matchingContainsRegistrationCredential = true
305-
break
306-
}
307-
}
308-
if vpContainsRegistrationCredential && !matchingContainsRegistrationCredential && len(presentation.VerifiableCredential)-len(creds) == 1 {
309-
return nil
310-
}
311-
312292
return errPresentationDoesNotFulfillDefinition
313293
}
314294
return nil

discovery/module_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ func TestModule_Search(t *testing.T) {
464464
{
465465
Presentation: vpAlice,
466466
Fields: map[string]interface{}{
467+
"auth_server_url":"https://example.com/oauth2/alice",
467468
"issuer_field": authorityDID,
468469
},
469470
Parameters: defaultRegistrationParams(aliceSubject),

discovery/test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ func testDefinitions() map[string]ServiceDefinition {
102102
},
103103
},
104104
},
105+
}, {
106+
Id: "2",
107+
Constraints: &pe.Constraints{
108+
Fields: []pe.Field{
109+
{
110+
Id: to.Ptr("auth_server_url"),
111+
Path: []string{"$.credentialSubject.authServerURL"},
112+
},
113+
},
114+
},
105115
},
106116
},
107117
},

docs/pages/deployment/discovery.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Optionally, a POST body can be provided with registration parameters, e.g.:
6060
6161
This can be used to provide additional information. All registration parameters are returned by the search API.
6262
The ``authServerURL`` is added automatically by the Nuts node. It's constructed as ``https://<config.url>/oauth2/<subject_id>``.
63+
Registration parameters can only be used if the specific parameters and/or ``DiscoveryRegistrationCredential`` are required by the Presentation Definition.
6364

6465
Once registered, future refreshes will be done automatically by the Nuts node. These refreshes could fail because of various reasons.
6566
You can check the status of the refreshes by querying the service, e.g.:
@@ -156,6 +157,18 @@ Service definitions
156157
}
157158
]
158159
}
160+
}, {
161+
"id": "DiscoveryRegistrationCredential",
162+
"constraints": {
163+
"fields": [
164+
{
165+
"id": "auth_server_url",
166+
"path": [
167+
"$.credentialSubject.authServerURL"
168+
]
169+
}
170+
]
171+
}
159172
}
160173
]
161174
}

e2e-tests/discovery/definitions/definition.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
}
4747
]
4848
}
49+
},{
50+
"id": "DiscoveryRegistrationCredential",
51+
"constraints": {
52+
"fields": [
53+
{
54+
"id": "auth_server_url",
55+
"path": [
56+
"$.credentialSubject.authServerURL"
57+
]
58+
}
59+
]
60+
}
4961
}
5062
]
5163
}

0 commit comments

Comments
 (0)