From c1f875c0c4a472b2dc424bc9de21a9cbdc8ca8ad Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 10 Nov 2019 10:21:10 +0100 Subject: [PATCH] fix: assert jwks is present for private_key_jwk first --- lib/helpers/client.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/helpers/client.js b/lib/helpers/client.js index ad12a7e5..63abdcf4 100644 --- a/lib/helpers/client.js +++ b/lib/helpers/client.js @@ -27,10 +27,16 @@ async function clientAssertion(endpoint, payload) { return jose.JWS.sign(payload, key, { alg, typ: 'JWT' }); } + const keystore = instance(this).get('keystore'); + + if (!keystore) { + throw new TypeError('no client jwks provided for signing a client assertion with'); + } + if (!alg) { const algs = new Set(); - instance(this).get('keystore').all().forEach((key) => { + keystore.all().forEach((key) => { key.algorithms('sign').forEach(Set.prototype.add.bind(algs)); }); @@ -38,13 +44,7 @@ async function clientAssertion(endpoint, payload) { alg = Array.isArray(supported) && supported.find((signAlg) => algs.has(signAlg)); } - const keystore = instance(this).get('keystore'); - - if (!keystore) { - throw new TypeError('no client jwks provided for signing a client assertion with'); - } - - const key = instance(this).get('keystore').get({ alg, use: 'sig' }); + const key = keystore.get({ alg, use: 'sig' }); if (!key) { throw new TypeError(`no key found in client jwks to sign a client assertion with using alg ${alg}`); }