From 0f0d0807a0031ff2a39c36be368ee0a71cebc617 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 25 Feb 2019 16:17:26 -0700 Subject: [PATCH] v1.1.4: fix fetching bug --- keyfetch-test.js | 10 +++++++--- keyfetch.js | 5 ++++- package.json | 6 ++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/keyfetch-test.js b/keyfetch-test.js index e60cc61..a7f7f8e 100644 --- a/keyfetch-test.js +++ b/keyfetch-test.js @@ -1,12 +1,16 @@ 'use strict'; var keyfetch = require('./keyfetch.js'); +var testUrl = "https://example.auth0.com"; keyfetch.init({}); -keyfetch.oidcJwks("https://bigsquid.auth0.com").then(function (jwks) { +keyfetch.oidcJwks().then(function (jwks) { + keyfetch._clear(); console.log(jwks); - return keyfetch.oidcJwk(jwks[0].thumbprint, "https://bigsquid.auth0.com").then(function (jwk) { - console.log(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); + }); }); }).catch(function (err) { console.error(err); diff --git a/keyfetch.js b/keyfetch.js index 996f6b6..9152e3f 100644 --- a/keyfetch.js +++ b/keyfetch.js @@ -22,6 +22,9 @@ function checkMinDefaultMax(opts, key, n, d, x) { } } +keyfetch._clear = function () { + keyCache = {}; +}; keyfetch.init = function (opts) { mincache = checkMinDefaultMax(opts, 'mincache', 1 * 60, @@ -113,7 +116,7 @@ keyfetch.oidcJwks = function (iss) { }; function checkId(id) { return function (results) { - var result = results.some(function (result) { + var result = results.filter(function (result) { // we already checked iss above return result.jwk.kid === id || result.thumbprint === id; })[0]; diff --git a/package.json b/package.json index 2b20389..70aec76 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,7 @@ }, "deprecated": false, "description": "Lightweight support for fetching JWKs.", - "files": [ - "keyfetch-test.js" - ], + "files": [], "keywords": [ "jwks", "jwk", @@ -31,5 +29,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "1.1.3" + "version": "1.1.4" }