v1.1.4: fix fetching bug

This commit is contained in:
AJ ONeal 2019-02-25 16:17:26 -07:00
parent cfe814ebb0
commit 0f0d0807a0
3 changed files with 13 additions and 8 deletions

View File

@ -1,13 +1,17 @@
'use strict'; 'use strict';
var keyfetch = require('./keyfetch.js'); var keyfetch = require('./keyfetch.js');
var testUrl = "https://example.auth0.com";
keyfetch.init({}); keyfetch.init({});
keyfetch.oidcJwks("https://bigsquid.auth0.com").then(function (jwks) { keyfetch.oidcJwks().then(function (jwks) {
keyfetch._clear();
console.log(jwks); console.log(jwks);
return keyfetch.oidcJwk(jwks[0].thumbprint, "https://bigsquid.auth0.com").then(function (jwk) { return keyfetch.oidcJwk(jwks[0].thumbprint, "https://example.auth0.com").then(function () {
return keyfetch.oidcJwk(jwks[0].thumbprint, "https://example.auth0.com").then(function (jwk) {
console.log(jwk); console.log(jwk);
}); });
});
}).catch(function (err) { }).catch(function (err) {
console.error(err); console.error(err);
}); });

View File

@ -22,6 +22,9 @@ function checkMinDefaultMax(opts, key, n, d, x) {
} }
} }
keyfetch._clear = function () {
keyCache = {};
};
keyfetch.init = function (opts) { keyfetch.init = function (opts) {
mincache = checkMinDefaultMax(opts, 'mincache', mincache = checkMinDefaultMax(opts, 'mincache',
1 * 60, 1 * 60,
@ -113,7 +116,7 @@ keyfetch.oidcJwks = function (iss) {
}; };
function checkId(id) { function checkId(id) {
return function (results) { return function (results) {
var result = results.some(function (result) { var result = results.filter(function (result) {
// we already checked iss above // we already checked iss above
return result.jwk.kid === id || result.thumbprint === id; return result.jwk.kid === id || result.thumbprint === id;
})[0]; })[0];

View File

@ -10,9 +10,7 @@
}, },
"deprecated": false, "deprecated": false,
"description": "Lightweight support for fetching JWKs.", "description": "Lightweight support for fetching JWKs.",
"files": [ "files": [],
"keyfetch-test.js"
],
"keywords": [ "keywords": [
"jwks", "jwks",
"jwk", "jwk",
@ -31,5 +29,5 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"version": "1.1.3" "version": "1.1.4"
} }