v1.1.2: DRY key check loop
This commit is contained in:
parent
6c071af9cd
commit
6d5c9d0097
54
keyfetch.js
54
keyfetch.js
|
@ -111,16 +111,11 @@ keyfetch.oidcJwks = function (iss) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
keyfetch.oidcJwk = function (id, iss) {
|
function checkId(id) {
|
||||||
// TODO [2] DRY this up a bit
|
return function (results) {
|
||||||
return keyfetch._checkCache(id, iss).then(function (hit) {
|
|
||||||
if (hit) {
|
|
||||||
return Promise.resolve(hit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyfetch.oidcJwks(iss).then(function (results) {
|
|
||||||
var result = results.some(function (result) {
|
var result = results.some(function (result) {
|
||||||
// we already checked iss above
|
// we already checked iss above
|
||||||
|
console.log(result);
|
||||||
return result.jwk.kid === id || result.thumbprint === id;
|
return result.jwk.kid === id || result.thumbprint === id;
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
|
@ -128,47 +123,24 @@ keyfetch.oidcJwk = function (id, iss) {
|
||||||
throw new Error("No JWK found by kid or thumbprint '" + id + "'");
|
throw new Error("No JWK found by kid or thumbprint '" + id + "'");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
keyfetch.oidcJwk = function (id, iss) {
|
||||||
|
return keyfetch._checkCache(id, iss).then(function (hit) {
|
||||||
|
if (hit) { return hit; }
|
||||||
|
return keyfetch.oidcJwks(iss).then(checkId(id));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
keyfetch.wellKnownJwk = function (id, iss) {
|
keyfetch.wellKnownJwk = function (id, iss) {
|
||||||
// TODO [2] DRY this up a bit
|
|
||||||
return keyfetch._checkCache(id, iss).then(function (hit) {
|
return keyfetch._checkCache(id, iss).then(function (hit) {
|
||||||
if (hit) {
|
if (hit) { return hit; }
|
||||||
return Promise.resolve(hit);
|
return keyfetch.wellKnownJwks(iss).then(checkId(id));
|
||||||
}
|
|
||||||
|
|
||||||
return keyfetch.wellKnownJwks(iss).then(function (results) {
|
|
||||||
var result = results.some(function (result) {
|
|
||||||
// we already checked iss above
|
|
||||||
return result.jwk.kid === id || result.thumbprint === id;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
throw new Error("No JWK found by kid or thumbprint '" + id + "'");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
keyfetch.jwk = function (id, jwksUrl) {
|
keyfetch.jwk = function (id, jwksUrl) {
|
||||||
// TODO [2] DRY this up a bit
|
|
||||||
return keyfetch._checkCache(id, jwksUrl).then(function (hit) {
|
return keyfetch._checkCache(id, jwksUrl).then(function (hit) {
|
||||||
if (hit) {
|
if (hit) { return hit; }
|
||||||
return Promise.resolve(hit);
|
return keyfetch.jwks(jwksUrl).then(checkId(id));
|
||||||
}
|
|
||||||
|
|
||||||
return keyfetch.jwks(jwksUrl).then(function (results) {
|
|
||||||
var result = results.some(function (result) {
|
|
||||||
// we already checked iss above
|
|
||||||
return result.jwk.kid === id || result.thumbprint === id;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
throw new Error("No JWK found by kid or thumbprint '" + id + "'");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
keyfetch._checkCache = function (id, iss) {
|
keyfetch._checkCache = function (id, iss) {
|
||||||
|
|
|
@ -31,5 +31,5 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"version": "1.1.1"
|
"version": "1.1.2"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue