@@ -54,7 +54,7 @@ const policyContainer = 'http://localhost:3000/ruben/settings/policies/';
5454async 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.
7575additionally, 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/>
7979PREFIX eu-gdpr: <https://w3id.org/dpv/legal/eu/gdpr#>
8080PREFIX oac: <https://w3id.org/oac#>
@@ -83,26 +83,25 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
8383
8484PREFIX 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.
240239There are two main points of work here: right now the claim token gathers all claims internally, as only a single token can be passed.
241240This 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
274273main ( ) ;
@@ -301,4 +300,3 @@ async function initContainer(policyContainer: string): Promise<void> {
301300 }
302301 }
303302}
304-
0 commit comments