-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauth.js
More file actions
26 lines (22 loc) · 749 Bytes
/
auth.js
File metadata and controls
26 lines (22 loc) · 749 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
const jwt = require('jsonwebtoken');
const jwksClient = require('jwks-rsa');
const client = jwksClient({
jwksUri: process.env.JWKS_URI
});
function getKey(header, callback) {
client.getSigningKey(header.kid, function (err, key) {
console.error(err);
const signingKey = key.publicKey || key.rsaPublicKey;
callback(null, signingKey);
});
}
function verifyUser(req, errFirstOrUserCallbackFunction) {
try{
const token = req.headers.authorization.split(' ')[1];
console.log(token);
jwt.verify(token, getKey, {}, errFirstOrUserCallbackFunction);
} catch (error) {
errFirstOrUserCallbackFunction('Authorized Personnel Only, bye felicia!');
}
}
module.exports = verifyUser;