Skip to content

Commit

Permalink
fix: assert jwks is present for private_key_jwk first
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Nov 10, 2019
1 parent 85c269b commit c1f875c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/helpers/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ 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));
});

const supported = this.issuer[`${endpoint}_endpoint_auth_signing_alg_values_supported`];
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}`);
}
Expand Down

0 comments on commit c1f875c

Please sign in to comment.