Skip to content

Commit

Permalink
fix(jwk retrieval): Fixing promise anti-pattern
Browse files Browse the repository at this point in the history
Not wrapping a promise in a promise
  • Loading branch information
tocco934 committed Apr 20, 2017
1 parent 9daceaf commit 7d8449c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/auth0verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const getExcludedRoutes = function (configuredExclusions) {
};

const getAuthPublicKey = function (jwksUrl, cache, kid) {
return new Promise((resolve, reject) => {
cache.get(`kid${kid}`).then(function (data) {
return cache.get(`kid${kid}`).then(function (data) {
if (!data) {
var client = jwksClient({
cache: true,
Expand All @@ -46,20 +45,19 @@ const getAuthPublicKey = function (jwksUrl, cache, kid) {
});
client.getSigningKey(kid, (err, key) => {
if (err) {
reject(err);
return err;
} else {
var signingKey = key.publicKey || key.rsaPublicKey;
var encodedValue = new Buffer(signingKey).toString("base64");
cache.set(`kid${kid}`, encodedValue, 36000).then(() => {
resolve(new Buffer(signingKey));
return new Buffer(signingKey);
});
}
});
} else {
resolve(new Buffer(data, "base64"));
return new Buffer(data, "base64");
}
});
});
};

// secures the application with auth0, by implementing checks against
Expand Down

0 comments on commit 7d8449c

Please sign in to comment.