1
This commit is contained in:
parent
ccaa2e8bee
commit
b29f7ab025
@ -4,10 +4,12 @@ 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) {
|
||||||
|
app.lock(LOCK_KEY + jkwsUri);
|
||||||
|
try {
|
||||||
if (jwksUri in jwksKeyHash) {
|
if (jwksUri in jwksKeyHash) {
|
||||||
const c = jwksKeyHash[jwksUri];
|
const c = jwksKeyHash[jwksUri];
|
||||||
cb(null, c['key']);
|
cb(null, c['key']);
|
||||||
@ -17,6 +19,7 @@ async function asyncGetKey(jkwsUri, header, cb) {
|
|||||||
jwksUri: jwksUri
|
jwksUri: jwksUri
|
||||||
});
|
});
|
||||||
client.getSigningKey(header.kid, function(err, key) {
|
client.getSigningKey(header.kid, function(err, key) {
|
||||||
|
try {
|
||||||
const signingKey = key.publicKey || key.rsaPublicKey;
|
const signingKey = key.publicKey || key.rsaPublicKey;
|
||||||
if (!err) {
|
if (!err) {
|
||||||
jwksKeyHash[jwksUri] = {
|
jwksKeyHash[jwksUri] = {
|
||||||
@ -25,7 +28,13 @@ async function asyncGetKey(jkwsUri, header, cb) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
cb(null, signingKey);
|
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