1
This commit is contained in:
parent
3b2e5fd410
commit
ccaa2e8bee
@ -5,8 +5,14 @@ const jwksClient = require('jwks-rsa');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const jwksKeyHash = {};
|
||||
const jwksKeyLockHash = {};
|
||||
|
||||
async function asyncGetKey(jkwsUri, header, cb) {
|
||||
if (jwksUri in jwksKeyHash) {
|
||||
const c = jwksKeyHash[jwksUri];
|
||||
cb(null, c['key']);
|
||||
return;
|
||||
}
|
||||
const client = jwksClient({
|
||||
jwksUri: jwksUri
|
||||
});
|
||||
@ -28,21 +34,18 @@ function asyncVerify(jwksUri, data) {
|
||||
err: null,
|
||||
decoded: null
|
||||
};
|
||||
function getKey(header, cb) {
|
||||
if (jwksUri in jwksKeyHash) {
|
||||
const c = jwksKeyHash[jwksUri];
|
||||
cb(null, c['key']);
|
||||
return;
|
||||
}
|
||||
jwt.verify
|
||||
(data,
|
||||
(header, cb) => {
|
||||
asyncGetKey(jwksUri, header, cb);
|
||||
}
|
||||
jwt.verify(data, getKey, function(err, decoded) {
|
||||
console.log(err);
|
||||
console.log(decoded);
|
||||
ret.err = err;
|
||||
ret.decoded = decoded;
|
||||
resolve(ret);
|
||||
});
|
||||
},
|
||||
(err, decoded) => {
|
||||
console.log(err);
|
||||
console.log(decoded);
|
||||
ret.err = err;
|
||||
ret.decoded = decoded;
|
||||
resolve(ret);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user