Skip to content

Commit 84611d6

Browse files
committed
fix: Update demo scripts to work with ODRL evaluator
1 parent 9460f81 commit 84611d6

3 files changed

Lines changed: 44 additions & 50 deletions

File tree

demo/flow-test.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function main() {
6565
log('Error fetching WebID data:', e);
6666
return;
6767
}
68-
68+
6969
const umaServer = webIdData.getObjects(terms.agents.ruben, terms.solid.umaServer, null)[0].value;
7070
const configUrl = new URL('.well-known/uma2-configuration', umaServer);
7171
const umaConfig = await (await fetch(configUrl)).json();
@@ -84,8 +84,8 @@ Target Resource: ${terms.resources.smartwatch}`)
8484
log('To protect this data, a policy is added restricting access to a specific healthcare employee for the purpose of bariatric care.');
8585
log(chalk.italic(`Note: Policy management is out of scope for POC1, right now they are just served from a public container on the pod.
8686
additionally, selecting relevant policies is not implemented at the moment, all policies are evaluated, but this is a minor fix in the AS.`))
87-
88-
const healthcare_patient_policy =
87+
88+
const healthcare_patient_policy =
8989
`@prefix dcterms: <http://purl.org/dc/terms/>.
9090
@prefix eu-gdpr: <https://w3id.org/dpv/legal/eu/gdpr#>.
9191
@prefix oac: <https://w3id.org/oac#>.
@@ -94,29 +94,28 @@ const healthcare_patient_policy =
9494
9595
@prefix ex: <http://example.org/>.
9696
97-
<http://example.org/HCPX-request> a odrl:Request ;
98-
odrl:uid ex:HCPX-request ;
97+
<http://example.org/HCPX-agreement> a odrl:Agreement ;
98+
odrl:uid ex:HCPX-agreement ;
9999
odrl:profile oac: ;
100-
dcterms:description "HCP X requests to read Alice's health data for bariatric care.";
101-
odrl:permission <http://example.org/HCPX-request-permission> .
100+
odrl:permission <http://example.org/HCPX-agreement-permission> .
102101
103-
<http://example.org/HCPX-request-permission> a odrl:Permission ;
102+
<http://example.org/HCPX-agreement-permission> a odrl:Permission ;
104103
odrl:action odrl:read ;
105104
odrl:target <http://example.org/medical-data-access-collection> ;
106105
odrl:assigner <${terms.agents.ruben}> ;
107106
odrl:assignee <${terms.agents.alice}> ;
108-
odrl:constraint <http://example.org/HCPX-request-permission-purpose>,
109-
<http://example.org/HCPX-request-permission-lb> .
107+
odrl:constraint <http://example.org/HCPX-agreement-permission-purpose>,
108+
<http://example.org/HCPX-agreement-permission-lb> .
110109
111110
<http://example.org/medical-data-access-collection> a odrl:AssetCollection;
112111
odrl:source <${terms.resources.collectionSource}> .
113112
114-
<http://example.org/HCPX-request-permission-purpose> a odrl:Constraint ;
113+
<http://example.org/HCPX-agreement-permission-purpose> a odrl:Constraint ;
115114
odrl:leftOperand odrl:purpose ; # can also be oac:Purpose, to conform with OAC profile
116115
odrl:operator odrl:eq ;
117116
odrl:rightOperand ex:bariatric-care .
118117
119-
<http://example.org/HCPX-request-permission-lb> a odrl:Constraint ;
118+
<http://example.org/HCPX-agreement-permission-lb> a odrl:Constraint ;
120119
odrl:leftOperand oac:LegalBasis ;
121120
odrl:operator odrl:eq ;
122121
odrl:rightOperand eu-gdpr:A9-2-a .`
@@ -211,7 +210,7 @@ const healthcare_patient_policy =
211210
],
212211
} ],
213212
// claims: [{
214-
claim_token: claim_token,
213+
claim_token: claim_token,
215214
claim_token_format: "urn:solidlab:uma:claims:formats:jwt",
216215
// }],
217216
// UMA specific fields
@@ -224,15 +223,15 @@ const healthcare_patient_policy =
224223
if (response2.failed) {
225224
throw new Error(`Resource request for ${terms.resources.smartwatch} should not have failed with claims: ${response}`)
226225
}
227-
226+
228227
const access_token = parseJwt(response2.access_token)
229228

230-
log(`The UMA server checks the claims with the relevant policy, and returns the agent an access token with the requested permissions.`,
229+
log(`The UMA server checks the claims with the relevant policy, and returns the agent an access token with the requested permissions.`,
231230
JSON.stringify(access_token.permissions, null, 2));
232-
233-
log(`and the accompanying agreement:`,
231+
232+
log(`and the accompanying agreement:`,
234233
JSON.stringify(access_token.contract, null, 2));
235-
234+
236235
log(chalk.italic(`Future work: at a later stage, this agreements will be signed by both parties to form a binding contract.`))
237236

238237
const accessWithTokenResponse = await fetch(terms.resources.smartwatch, {
@@ -242,7 +241,7 @@ const healthcare_patient_policy =
242241
log(`Now the doctor can retrieve the resource:`, await accessWithTokenResponse.text());
243242

244243
if (accessWithTokenResponse.status !== 200) { log(`Access with token failed...`); throw 0; }
245-
244+
246245
}
247246

248247
main();
@@ -270,7 +269,7 @@ async function executeReadWithClaims(target: string, request: any, options: { to
270269
method: "GET",
271270
headers: { "content-type": "application/json" },
272271
});
273-
272+
274273
const umaHeader = await res.headers.get('WWW-Authenticate')
275274

276275
log(`Resource request to ${target} results in ${umaHeader}`)
@@ -287,7 +286,7 @@ async function executeReadWithClaims(target: string, request: any, options: { to
287286
headers: { "content-type": "application/json" },
288287
body: JSON.stringify(request),
289288
});
290-
289+
291290
// if (response.status !== 403) { log('Access request succeeded without claims...', await response.text()); throw 0; }
292291

293292
const responseJSON = await response.json();

demo/flow.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const policyContainer = 'http://localhost:3000/ruben/settings/policies/';
5454
async function main() {
5555

5656
const webIdData = new Store(parser.parse(await (await fetch(terms.agents.ruben)).text()));
57-
57+
5858
const umaServer = webIdData.getObjects(terms.agents.ruben, terms.solid.umaServer, null)[0].value;
5959
const configUrl = new URL('.well-known/uma2-configuration', umaServer);
6060
const umaConfig = await (await fetch(configUrl)).json();
@@ -73,8 +73,8 @@ Target Resource: ${terms.resources.smartwatch}`)
7373
log('To protect this data, a policy is added restricting access to a specific healthcare employee for the purpose of bariatric care.');
7474
log(chalk.italic(`Note: Policy management is out of scope for POC1, right now they are just served from a public container on the pod.
7575
additionally, selecting relevant policies is not implemented at the moment, all policies are evaluated, but this is a minor fix in the AS.`))
76-
77-
const healthcare_patient_policy =
76+
77+
const healthcare_patient_policy =
7878
`PREFIX dcterms: <http://purl.org/dc/terms/>
7979
PREFIX eu-gdpr: <https://w3id.org/dpv/legal/eu/gdpr#>
8080
PREFIX oac: <https://w3id.org/oac#>
@@ -83,26 +83,25 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
8383
8484
PREFIX ex: <http://example.org/>
8585
86-
<http://example.org/HCPX-request> a odrl:Request ;
87-
odrl:uid ex:HCPX-request ;
86+
<http://example.org/HCPX-agreement> a odrl:Agreement ;
87+
odrl:uid ex:HCPX-agreement ;
8888
odrl:profile oac: ;
89-
dcterms:description "HCP X requests to read Alice's health data for bariatric care.";
90-
odrl:permission <http://example.org/HCPX-request-permission> .
89+
odrl:permission <http://example.org/HCPX-agreement-permission> .
9190
92-
<http://example.org/HCPX-request-permission> a odrl:Permission ;
91+
<http://example.org/HCPX-agreement-permission> a odrl:Permission ;
9392
odrl:action odrl:read ;
9493
odrl:target <${terms.resources.smartwatch}> ;
9594
odrl:assigner <${terms.agents.ruben}> ;
9695
odrl:assignee <${terms.agents.alice}> ;
97-
odrl:constraint <http://example.org/HCPX-request-permission-purpose>,
98-
<http://example.org/HCPX-request-permission-lb> .
96+
odrl:constraint <http://example.org/HCPX-agreement-permission-purpose>,
97+
<http://example.org/HCPX-agreement-permission-lb> .
9998
100-
<http://example.org/HCPX-request-permission-purpose> a odrl:Constraint ;
99+
<http://example.org/HCPX-agreement-permission-purpose> a odrl:Constraint ;
101100
odrl:leftOperand odrl:purpose ; # can also be oac:Purpose, to conform with OAC profile
102101
odrl:operator odrl:eq ;
103102
odrl:rightOperand ex:bariatric-care .
104103
105-
<http://example.org/HCPX-request-permission-lb> a odrl:Constraint ;
104+
<http://example.org/HCPX-agreement-permission-lb> a odrl:Constraint ;
106105
odrl:leftOperand oac:LegalBasis ;
107106
odrl:operator odrl:eq ;
108107
odrl:rightOperand eu-gdpr:A9-2-a .`
@@ -129,7 +128,7 @@ on the condition of the purpose of the request being "http://example.org/bariatr
129128
method: "GET",
130129
headers: { "content-type": "application/json" },
131130
});
132-
131+
133132
const umaHeader = await res.headers.get('WWW-Authenticate')
134133

135134
log(`First, a resource request is done without authorization that results in a 403 response and accompanying UMA ticket in the WWW-Authenticate header according to the UMA specification:
@@ -164,12 +163,12 @@ ${umaHeader}`)
164163
headers: { "content-type": "application/json" },
165164
body: JSON.stringify(smartWatchAccessRequestNoClaimsODRL),
166165
});
167-
166+
168167
if (doctor_needInfoResponse.status !== 403) { log('Access request succeeded without claims...', await doctor_needInfoResponse.text()); throw 0; }
169168

170169
const { ticket: ticket2, required_claims: doctor_claims } = await doctor_needInfoResponse.json();
171170
ticket = ticket2
172-
171+
173172
log(`Based on the policy set above, the Authorization Server requests the following claims from the doctor:`);
174173
doctor_claims.claim_token_format[0].forEach((format: string) => log(` - ${format}`))
175174
log(`accompanied by an updated ticket: ${ticket}.`)
@@ -225,7 +224,7 @@ ${umaHeader}`)
225224
],
226225
} ],
227226
// claims: [{
228-
claim_token: claim_token,
227+
claim_token: claim_token,
229228
claim_token_format: "urn:solidlab:uma:claims:formats:jwt",
230229
// }],
231230
// UMA specific fields
@@ -235,7 +234,7 @@ ${umaHeader}`)
235234

236235
log('Together with the UMA grant_type and ticket requirements, these are bundled as an ODRL Request and sent back to the Authorization Server')
237236
log(JSON.stringify(smartWatchAccessRequestODRL, null, 2))
238-
237+
239238
log(chalk.italic(`Note: the ODRL Request constraints are not yet evaluated as claims, only the passed claim token is.
240239
There are two main points of work here: right now the claim token gathers all claims internally, as only a single token can be passed.
241240
This is problematic when claims and OIDC tokens have to be passed. It might be worth looking deeper into ODRL requests to carry these claims instead of an UMA token.`))
@@ -246,19 +245,19 @@ This is problematic when claims and OIDC tokens have to be passed. It might be w
246245
body: JSON.stringify(smartWatchAccessRequestODRL)
247246
});
248247

249-
if (accessGrantedResponse.status !== 200) {
250-
log('Access request failed despite policy...', JSON.stringify(await accessGrantedResponse.text(), null, 2)); throw 0;
248+
if (accessGrantedResponse.status !== 200) {
249+
log('Access request failed despite policy...', JSON.stringify(await accessGrantedResponse.text(), null, 2)); throw 0;
251250
}
252251

253252
const tokenParams = await accessGrantedResponse.json();
254253
const access_token = parseJwt(tokenParams.access_token)
255254

256-
log(`The UMA server checks the claims with the relevant policy, and returns the agent an access token with the requested permissions.`,
255+
log(`The UMA server checks the claims with the relevant policy, and returns the agent an access token with the requested permissions.`,
257256
JSON.stringify(access_token.permissions, null, 2));
258-
259-
log(`and the accompanying agreement:`,
257+
258+
log(`and the accompanying agreement:`,
260259
JSON.stringify(access_token.contract, null, 2));
261-
260+
262261
log(chalk.italic(`Future work: at a later stage, this agreements will be signed by both parties to form a binding contract.`))
263262

264263
const accessWithTokenResponse = await fetch(terms.resources.smartwatch, {
@@ -268,7 +267,7 @@ This is problematic when claims and OIDC tokens have to be passed. It might be w
268267
log(`Now the doctor can retrieve the resource:`, await accessWithTokenResponse.text());
269268

270269
if (accessWithTokenResponse.status !== 200) { log(`Access with token failed...`); throw 0; }
271-
270+
272271
}
273272

274273
main();
@@ -301,4 +300,3 @@ async function initContainer(policyContainer: string): Promise<void> {
301300
}
302301
}
303302
}
304-

packages/uma/config/demo.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
"@id": "urn:uma:default:AllAuthorizer"
3434
}
3535
}
36-
],
37-
"fallback": {
38-
"@id": "urn:uma:default:PolicyBasedAuthorizer"
39-
}
36+
]
4037
}
4138
},
4239
{

0 commit comments

Comments
 (0)