tangled
alpha
login
or
join now
bad-example.com
/
spacedust-utils
6
fork
atom
demos for spacedust
6
fork
atom
overview
issues
pulls
pipelines
log jwks errors
bad-example.com
8 months ago
3e91b8ce
10cf2371
+6
-5
1 changed file
expand all
collapse all
unified
split
server
index.js
+6
-5
server/index.js
···
240
240
}
241
241
};
242
242
243
243
-
const handleVerify = async (db, req, res, whoamiHost, appSecret) => {
244
244
-
const jwks = jose.createRemoteJWKSet(new URL(`${whoamiHost}/.well-known/jwks.json`));
243
243
+
const handleVerify = async (db, req, res, whoamiHost, jwks, appSecret) => {
245
244
const body = await getRequesBody(req);
246
245
const { token } = JSON.parse(body);
247
246
let did;
···
249
248
const verified = await jose.jwtVerify(token, jwks);
250
249
did = verified.payload.sub;
251
250
} catch (e) {
251
251
+
console.warn('jwks verification failed', e);
252
252
return clearAccountCookie(res).writeHead(400).end(JSON.stringify({ reason: 'verification failed' }));
253
253
}
254
254
db.addAccount(did);
···
271
271
res.end(JSON.stringify({ sup: 'hi' }));
272
272
};
273
273
274
274
-
const requestListener = (secrets, whoamiHost, db, adminDid) => (req, res) => {
274
274
+
const requestListener = (secrets, jwks, whoamiHost, db, adminDid) => (req, res) => {
275
275
if (req.method === 'GET' && req.url === '/') {
276
276
return handleIndex(req, res, { PUBKEY: secrets.pushKeys.publicKey });
277
277
}
···
293
293
}
294
294
if (req.method === 'POST' && req.url === '/verify') {
295
295
res.setHeaders(new Headers(CORS_PERMISSIVE(req)));
296
296
-
return handleVerify(db, req, res, whoamiHost, secrets.appSecret);
296
296
+
return handleVerify(db, req, res, whoamiHost, jwks, secrets.appSecret);
297
297
}
298
298
299
299
if (req.method === 'OPTIONS' && req.url === '/subscribe') {
···
322
322
);
323
323
324
324
const whoamiHost = env.WHOAMI_HOST ?? 'https://who-am-i.microcosm.blue';
325
325
+
const jwks = jose.createRemoteJWKSet(new URL(`${whoamiHost}/.well-known/jwks.json`));
325
326
326
327
const dbFilename = env.DB_FILE ?? './db.sqlite3';
327
328
const initDb = process.argv.includes('--init-db');
···
335
336
const port = parseInt(env.PORT ?? 8000, 10);
336
337
337
338
http
338
338
-
.createServer(requestListener(secrets, whoamiHost, db, adminDid))
339
339
+
.createServer(requestListener(secrets, jwks, whoamiHost, db, adminDid))
339
340
.listen(port, host, () => console.log(`listening at http://${host}:${port}`));
340
341
};
341
342