-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsolidcommunity-interop.js
More file actions
126 lines (106 loc) · 3.77 KB
/
Copy pathsolidcommunity-interop.js
File metadata and controls
126 lines (106 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Test on solidcommunity.net to confirm DPoP auth works
*/
const fetch = require('node-fetch');
const jose = require('jose');
const crypto = require('crypto');
const ISSUER = 'https://melvincarvalho.com/';
async function test() {
console.log('=== Confirming DPoP works on solidcommunity.net ===\n');
const { publicKey, privateKey } = await jose.generateKeyPair('ES256');
const publicJwk = await jose.exportJWK(publicKey);
const credDpopProof = await new jose.SignJWT({
htm: 'POST',
htu: ISSUER + 'idp/credentials',
iat: Math.floor(Date.now() / 1000),
jti: crypto.randomUUID(),
})
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
.sign(privateKey);
const tokenResp = await fetch(ISSUER + 'idp/credentials', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'DPoP': credDpopProof },
body: JSON.stringify({ email: 'melvin', password: 'melvintest123' }),
});
const tokenData = await tokenResp.json();
const access_token = tokenData.access_token;
console.log('Got token, webid:', tokenData.webid);
// Parse token
const payload = JSON.parse(Buffer.from(access_token.split('.')[1], 'base64url').toString());
console.log('Token issuer:', payload.iss);
console.log('Token webid:', payload.webid);
console.log('Token cnf.jkt:', payload.cnf.jkt.substring(0, 20) + '...');
// Test different endpoints on solidcommunity.net
const tests = [
{ url: 'https://solidcommunity.net/', name: 'root (public)' },
{ url: 'https://melvin.solidcommunity.net/', name: 'user pod root' },
{ url: 'https://melvin.solidcommunity.net/profile/card', name: 'user profile' },
];
for (const t of tests) {
console.log('\n--- ' + t.name + ' ---');
console.log('URL:', t.url);
// Without auth
const noAuthResp = await fetch(t.url, {
headers: { 'Accept': 'text/turtle' },
});
console.log('Without auth:', noAuthResp.status);
// With DPoP
const dpopProof = await new jose.SignJWT({
htm: 'GET',
htu: t.url,
iat: Math.floor(Date.now() / 1000),
jti: crypto.randomUUID(),
})
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
.sign(privateKey);
const authResp = await fetch(t.url, {
headers: {
'Authorization': 'DPoP ' + access_token,
'DPoP': dpopProof,
'Accept': 'text/turtle',
},
});
console.log('With DPoP:', authResp.status);
const wwwAuth = authResp.headers.get('www-authenticate');
if (wwwAuth) {
console.log('WWW-Auth:', wwwAuth);
}
}
// Now compare the same tests on solidweb.org
console.log('\n\n=== Comparison: Same tests on solidweb.org ===\n');
const swTests = [
{ url: 'https://solidweb.org/', name: 'root (public)' },
{ url: 'https://solid-chat.solidweb.org/', name: 'solid-chat pod root' },
];
for (const t of swTests) {
console.log('\n--- ' + t.name + ' ---');
console.log('URL:', t.url);
// Without auth
const noAuthResp = await fetch(t.url, {
headers: { 'Accept': 'text/turtle' },
});
console.log('Without auth:', noAuthResp.status);
// With DPoP
const dpopProof = await new jose.SignJWT({
htm: 'GET',
htu: t.url,
iat: Math.floor(Date.now() / 1000),
jti: crypto.randomUUID(),
})
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
.sign(privateKey);
const authResp = await fetch(t.url, {
headers: {
'Authorization': 'DPoP ' + access_token,
'DPoP': dpopProof,
'Accept': 'text/turtle',
},
});
console.log('With DPoP:', authResp.status);
const wwwAuth = authResp.headers.get('www-authenticate');
if (wwwAuth) {
console.log('WWW-Auth:', wwwAuth);
}
}
}
test().catch(console.error);