forked from ChrisWiles/React-todoMVC
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauth.js
More file actions
28 lines (24 loc) · 663 Bytes
/
auth.js
File metadata and controls
28 lines (24 loc) · 663 Bytes
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
const jwt = require("jsonwebtoken");
const jwksClient = require("jwks-rsa");
const { promisify } = require("util");
const jwtVerify = promisify(jwt.verify);
const client = jwksClient({
cache: true,
jwksUri: process.env.JWKS_URI,
});
function getKey(header, callback) {
client.getSigningKey(header.kid, function(err, key) {
if (err) {
return callback(err);
}
var signingKey = key.publicKey || key.rsaPublicKey;
callback(null, signingKey);
});
}
module.exports = async function parseClaims(req) {
const token = req.cookies.token;
if (!token) {
throw "No token provided";
}
return await jwtVerify(token, getKey, {});
};