demos for spacedust

log jwks errors

+6 -5
+6 -5
server/index.js
··· 240 240 } 241 241 }; 242 242 243 - const handleVerify = async (db, req, res, whoamiHost, appSecret) => { 244 - const jwks = jose.createRemoteJWKSet(new URL(`${whoamiHost}/.well-known/jwks.json`)); 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 + 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 - const requestListener = (secrets, whoamiHost, db, adminDid) => (req, res) => { 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 - return handleVerify(db, req, res, whoamiHost, secrets.appSecret); 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 + 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 - .createServer(requestListener(secrets, whoamiHost, db, adminDid)) 339 + .createServer(requestListener(secrets, jwks, whoamiHost, db, adminDid)) 339 340 .listen(port, host, () => console.log(`listening at http://${host}:${port}`)); 340 341 }; 341 342