1
This commit is contained in:
parent
ccaa2e8bee
commit
b29f7ab025
@ -4,28 +4,37 @@ const base64url = require('base64url');
|
|||||||
const jwksClient = require('jwks-rsa');
|
const jwksClient = require('jwks-rsa');
|
||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
|
const LOCK_KEY = 'getJwtLock:';
|
||||||
const jwksKeyHash = {};
|
const jwksKeyHash = {};
|
||||||
const jwksKeyLockHash = {};
|
|
||||||
|
|
||||||
async function asyncGetKey(jkwsUri, header, cb) {
|
async function asyncGetKey(jkwsUri, header, cb) {
|
||||||
if (jwksUri in jwksKeyHash) {
|
app.lock(LOCK_KEY + jkwsUri);
|
||||||
const c = jwksKeyHash[jwksUri];
|
try {
|
||||||
cb(null, c['key']);
|
if (jwksUri in jwksKeyHash) {
|
||||||
return;
|
const c = jwksKeyHash[jwksUri];
|
||||||
}
|
cb(null, c['key']);
|
||||||
const client = jwksClient({
|
return;
|
||||||
jwksUri: jwksUri
|
|
||||||
});
|
|
||||||
client.getSigningKey(header.kid, function(err, key) {
|
|
||||||
const signingKey = key.publicKey || key.rsaPublicKey;
|
|
||||||
if (!err) {
|
|
||||||
jwksKeyHash[jwksUri] = {
|
|
||||||
'key': key,
|
|
||||||
'lastRefreshTime': utils.getUtcTime()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
cb(null, signingKey);
|
const client = jwksClient({
|
||||||
});
|
jwksUri: jwksUri
|
||||||
|
});
|
||||||
|
client.getSigningKey(header.kid, function(err, key) {
|
||||||
|
try {
|
||||||
|
const signingKey = key.publicKey || key.rsaPublicKey;
|
||||||
|
if (!err) {
|
||||||
|
jwksKeyHash[jwksUri] = {
|
||||||
|
'key': key,
|
||||||
|
'lastRefreshTime': utils.getUtcTime()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
cb(null, signingKey);
|
||||||
|
} finally {
|
||||||
|
app.unLock(LOCK_KEY + jkwsUri);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
app.unLock(LOCK_KEY + jkwsUri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function asyncVerify(jwksUri, data) {
|
function asyncVerify(jwksUri, data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user