Skip to content

Commit 3ace0e3

Browse files
committed
chore: clean up scripts for demo
Signed-off-by: Wouter Termont <wouter.termont@ugent.be>
1 parent e01d610 commit 3ace0e3

File tree

5 files changed

+90
-105
lines changed

5 files changed

+90
-105
lines changed

packages/css/src/util/OwnerUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class OwnerUtil {
5050
this.logger.debug(`Looking up owners of pod ${pod.id}`);
5151

5252
const as = await this.accountStore.getSetting(pod.accountId, ACCOUNT_SETTINGS_AUTHZ_SERVER);
53-
this.logger.warn(`REAL AS is ${JSON.stringify(as)}`);
53+
// this.logger.warn(`REAL AS is ${JSON.stringify(as)}`);
5454

5555
const owners = await this.podStore.getOwners(pod.id);
5656
if (!owners) throw new Error(`Unable to find owners for pod ${storage.path}`);

scripts/test-private.ts

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,69 @@ const request: RequestInit = {
1414

1515
async function main() {
1616

17-
console.log(`3.1 Send request to protected resource (${privateResource}) without access token.`);
18-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.1
19-
// 3.1 Client Requests Resource Without Providing an Access Token
17+
console.log('\n\n');
18+
19+
console.log(`=== Trying to create private resource <${privateResource}> without access token.\n`);
20+
2021
const noTokenResponse = await fetch(privateResource, request);
2122

22-
console.log("3.2 Resource Server Responds to Client's Tokenless Access Attempt");
23-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.2
24-
// 3.2 Resource Server Responds to Client's Tokenless Access Attempt
25-
console.log(noTokenResponse.status);
26-
console.log(await noTokenResponse.text());
2723
const wwwAuthenticateHeader = noTokenResponse.headers.get("WWW-Authenticate")!
28-
// Note: needs errorhandling when not present
29-
console.log(wwwAuthenticateHeader);
24+
25+
console.log(`= Status: ${noTokenResponse.status}\n`);
26+
console.log(`= Www-Authenticate header: ${wwwAuthenticateHeader}\n`);
27+
console.log('');
3028

3129
const { as_uri, ticket } = Object.fromEntries(wwwAuthenticateHeader.replace(/^UMA /,'').split(', ').map(
3230
param => param.split('=').map(s => s.replace(/"/g,''))
3331
));
34-
console.log(as_uri);
35-
console.log(ticket);
3632

3733
const tokenEndpoint = as_uri + "/token" // should normally be retrieved from .well-known/uma2-configuration
3834

39-
// the claim that I am that person?
40-
// const claim_token = "http://localhost:3000/alice/profile/card#me"
4135
const claim_token = "https://woslabbi.pod.knows.idlab.ugent.be/profile/card#me"
4236

43-
console.log(`3.3.1 Client Request to Authorization Server (${as_uri}) for RPT`);
44-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.1
45-
// 3.3.1 Client Request to Authorization Server for RPT
46-
const body = JSON.stringify({
37+
const content = {
4738
grant_type: 'urn:ietf:params:oauth:grant-type:uma-ticket',
4839
ticket,
4940
claim_token: encodeURIComponent(claim_token),
5041
claim_token_format: 'urn:solidlab:uma:claims:formats:webid',
51-
});
52-
console.log("Token request body: ", body);
42+
};
43+
44+
console.log(`=== Requesting token at ${tokenEndpoint} with ticket body:\n`);
45+
console.log(content);
46+
console.log('');
47+
5348
const asRequestResponse = await fetch(tokenEndpoint, {
5449
method: "POST",
5550
headers: {
5651
"content-type":"application/json"
5752
},
58-
body
53+
body: JSON.stringify(content),
5954
})
6055

56+
// For debugging:
6157
// console.log("Authorization Server response:", await asRequestResponse.text());
6258
// throw 'stop'
63-
const asResponse = await asRequestResponse.json()
64-
console.log("Authorization Server response:", asResponse);
6559

66-
console.log(`3.3.5 Authorization Server Response to Client on Authorization Success:`);
67-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.5 or https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.6
68-
// 3.3.5 or 3.3.6 Authorization Server Response to Client on Authorization Success or Failure
69-
// Note: it is required to have a debug uma server loaded
60+
const asResponse = await asRequestResponse.json();
7061

7162
const decodedToken = parseJwt(asResponse.access_token);
7263

73-
console.log("Access token decoded:",decodedToken)
74-
for (const permission of decodedToken.permissions) {
75-
console.log(`Permissioned scopes for resource ${permission.resource_id}:`, permission.resource_scopes)
64+
console.log(`= Status: ${asRequestResponse.status}\n`);
65+
console.log(`= Body (decoded):\n`);
66+
console.log({ ...asResponse, access_token: asResponse.access_token.slice(0,10).concat('...') });
67+
console.log('\n');
7668

77-
}
69+
// for (const permission of decodedToken.permissions) {
70+
// console.log(`Permissioned scopes for resource ${permission.resource_id}:`, permission.resource_scopes)
71+
// }
7872

79-
console.log(`3.4 Client Requests Resource and Provides an RPT`);
80-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.4
81-
// 3.4 Client Requests Resource and Provides an RPT
82-
// Only in happy flow (when we get a success 3.3.5)
73+
console.log(`=== Trying to create private resource <${privateResource}> WITH access token.\n`);
74+
8375
request.headers = { 'Authorization': `${asResponse.token_type} ${asResponse.access_token}` };
76+
8477
const tokenResponse = await fetch(privateResource, request);
8578

86-
console.log(`3.5 Resource Server Responds to Client's RPT-Accompanied Resource Request:`);
87-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.5
88-
// 3.5 Resource Server Responds to Client's RPT-Accompanied Resource Request
89-
console.log(tokenResponse.status);
79+
console.log(`= Status: ${tokenResponse.status}\n`);
9080
}
91-
main()
81+
82+
main();

scripts/test-public.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { fetch } from 'cross-fetch'
33
const publicResource = "http://localhost:3000/alice/profile/card"
44

55
async function main() {
6-
console.log(`=== Trying to read public resource <${publicResource}> without access token.`);
6+
7+
console.log('\n\n');
8+
9+
console.log(`=== Trying to read public resource <${publicResource}> without access token.\n`);
710

811
const publicResponse = await fetch(publicResource, { method: "GET" });
9-
10-
console.log(`= Status: ${publicResponse.status}`);
11-
console.log(`= Body: \n${await publicResponse.text()}`);
12+
13+
console.log(`= Status: ${publicResponse.status}\n`);
14+
console.log(`= Body:\n \n${await publicResponse.text()}\n`);
1215
}
1316

14-
main();
17+
main();

scripts/test-registration.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
import { fetch } from 'cross-fetch'
22

3-
const container = "http://localhost:3000/alice/public/"
4-
const slug = "resource.txt"
3+
const container = "http://localhost:3000/alice/public/";
4+
const slug = "resource.txt";
5+
const body = "This is a resource.";
56

67
async function main() {
78

8-
console.log("=== Creating container (if needed) ...")
9+
console.log(`=== PUT container <${container}>\n`);
910

1011
const containerResponse = await fetch(container, {
1112
method: "PUT",
1213
})
1314

14-
console.log(`= Status: ${containerResponse.status}`);
15+
console.log(`= Status: ${containerResponse.status}\n`);
16+
console.log('\n');
1517

16-
console.log("=== Creating resource ...")
18+
console.log(`=== POST to <${container}> with slug '${slug}': "${body}"\n`)
1719

1820
const createResponse = await fetch(container, {
1921
method: "POST",
2022
headers: { slug },
21-
body: "This is a resource."
23+
body
2224
})
2325

24-
console.log(`= Status: ${createResponse.status}`);
26+
console.log(`= Status: ${createResponse.status}\n`);
27+
console.log('\n');
2528

26-
console.log("=== Creating resource ...")
29+
console.log(`=== GET <${container + slug}>\n`);
2730

2831
const readResponse = await fetch(container + slug, {
2932
method: "GET",
3033
})
3134

32-
console.log(`= Status: ${readResponse.status}`);
33-
console.log(`= Body: \n${await readResponse.text()}`);
34-
35-
console.log("=== Deleting resource ...")
35+
console.log(`= Status: ${readResponse.status}\n`);
36+
console.log(`= Body: "${await readResponse.text()}"\n`);
37+
console.log('\n');
3638

39+
console.log(`=== DELETE <${container + slug}>\n`);
3740

3841
const deleteResponse = await fetch(container + slug, {
3942
method: "DELETE",
4043
})
4144

42-
console.log(`= Status: ${deleteResponse.status}`);
43-
45+
console.log(`= Status: ${deleteResponse.status}\n`);
4446
}
4547

46-
main();
48+
main();

scripts/test-uma-ucp.ts

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fetch } from 'cross-fetch'
22

33
// Resource and WebID as set in config/rules/policy/policy0.ttl
4-
const resource = "http://localhost:3000/alice/other/resource.txt"
4+
const resource = "http://localhost:3000/alice/other/resource.txt";
55
const webid = "https://woslabbi.pod.knows.idlab.ugent.be/profile/card#me";
66

77
function parseJwt (token:string) {
@@ -16,78 +16,67 @@ const request: RequestInit = {
1616

1717
async function main() {
1818

19-
console.log(`3.1 Send request to protected resource (${resource}) without access token.`);
20-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.1
21-
// 3.1 Client Requests Resource Without Providing an Access Token
19+
console.log('\n\n');
20+
21+
console.log(`=== Trying to create private resource <${resource}> without access token.\n`);
22+
2223
const noTokenResponse = await fetch(resource, request);
2324

24-
console.log("3.2 Resource Server Responds to Client's Tokenless Access Attempt");
25-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.2
26-
// 3.2 Resource Server Responds to Client's Tokenless Access Attempt
27-
console.log(noTokenResponse.status);
28-
console.log(await noTokenResponse.text());
2925
const wwwAuthenticateHeader = noTokenResponse.headers.get("WWW-Authenticate")!
30-
// Note: needs errorhandling when not present
31-
console.log(wwwAuthenticateHeader);
26+
27+
console.log(`= Status: ${noTokenResponse.status}\n`);
28+
console.log(`= Www-Authenticate header: ${wwwAuthenticateHeader}\n`);
29+
console.log('');
3230

3331
const { as_uri, ticket } = Object.fromEntries(wwwAuthenticateHeader.replace(/^UMA /,'').split(', ').map(
3432
param => param.split('=').map(s => s.replace(/"/g,''))
3533
));
36-
console.log(as_uri);
37-
console.log(ticket);
3834

3935
const tokenEndpoint = as_uri + "/token" // should normally be retrieved from .well-known/uma2-configuration
4036

41-
// the claim that I am that person?
42-
// const claim_token = "http://localhost:3000/alice/profile/card#me"
43-
const claim_token = webid;
44-
45-
console.log(`3.3.1 Client Request to Authorization Server (${as_uri}) for RPT`);
46-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.1
47-
// 3.3.1 Client Request to Authorization Server for RPT
48-
const body = JSON.stringify({
37+
const content = {
4938
grant_type: 'urn:ietf:params:oauth:grant-type:uma-ticket',
5039
ticket,
51-
claim_token: encodeURIComponent(claim_token),
40+
claim_token: encodeURIComponent(webid),
5241
claim_token_format: 'urn:solidlab:uma:claims:formats:webid',
53-
});
54-
console.log("Token request body: ", body);
42+
};
43+
44+
console.log(`=== Requesting token at ${tokenEndpoint} with ticket body:\n`);
45+
console.log(content);
46+
console.log('');
47+
5548
const asRequestResponse = await fetch(tokenEndpoint, {
5649
method: "POST",
5750
headers: {
5851
"content-type":"application/json"
5952
},
60-
body
53+
body: JSON.stringify(content),
6154
})
6255

56+
// For debugging:
6357
// console.log("Authorization Server response:", await asRequestResponse.text());
6458
// throw 'stop'
65-
const asResponse = await asRequestResponse.json()
66-
console.log("Authorization Server response:", asResponse);
6759

68-
console.log(`3.3.5 Authorization Server Response to Client on Authorization Success:`);
69-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.5 or https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.6
70-
// 3.3.5 or 3.3.6 Authorization Server Response to Client on Authorization Success or Failure
71-
// Note: it is required to have a debug uma server loaded
60+
const asResponse = await asRequestResponse.json()
7261

7362
const decodedToken = parseJwt(asResponse.access_token);
7463

75-
console.log("Access token decoded:",decodedToken)
76-
for (const permission of decodedToken.permissions) {
77-
console.log(`Permissioned scopes for resource ${permission.resource_id}:`, permission.resource_scopes)
64+
console.log(`= Status: ${asRequestResponse.status}\n`);
65+
console.log(`= Body (decoded):\n`);
66+
console.log({ ...asResponse, access_token: asResponse.access_token.slice(0,10).concat('...') });
67+
console.log('\n');
68+
69+
// for (const permission of decodedToken.permissions) {
70+
// console.log(`Permissioned scopes for resource ${permission.resource_id}:`, permission.resource_scopes)
71+
// }
7872

79-
}
73+
console.log(`=== Trying to create private resource <${resource}> WITH access token.\n`);
8074

81-
console.log(`3.4 Client Requests Resource and Provides an RPT`);
82-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.4
83-
// 3.4 Client Requests Resource and Provides an RPT
84-
// Only in happy flow (when we get a success 3.3.5)
8575
request.headers = { 'Authorization': `${asResponse.token_type} ${asResponse.access_token}` };
76+
8677
const tokenResponse = await fetch(resource, request);
8778

88-
console.log(`3.5 Resource Server Responds to Client's RPT-Accompanied Resource Request:`);
89-
// https://docs.kantarainitiative.org/uma/wg/rec-oauth-uma-grant-2.0.html#rfc.section.3.3.5
90-
// 3.5 Resource Server Responds to Client's RPT-Accompanied Resource Request
91-
console.log(tokenResponse.status);
79+
console.log(`= Status: ${tokenResponse.status}\n`);
9280
}
93-
main()
81+
82+
main();

0 commit comments

Comments
 (0)