Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling case when Jwk doesn't have 'use' parameter #116

Merged
merged 6 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JwksClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class JwksClient {
}

const signingKeys = keys
.filter(key => key.use === 'sig' && key.kty === 'RSA' && key.kid && ((key.x5c && key.x5c.length) || (key.n && key.e)))
.filter(key => (!key.use || key.use === 'sig') && key.kty === 'RSA' && key.kid && ((key.x5c && key.x5c.length) || (key.n && key.e)))
lbalmaceda marked this conversation as resolved.
Show resolved Hide resolved
.map(key => {
if (key.x5c && key.x5c.length) {
return {
Expand Down
23 changes: 21 additions & 2 deletions tests/jwksClient.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,25 @@ describe("JwksClient", () => {
e: "AQAB",
n:
"s4W7xjkQZP3OwG7PfRgcYKn8eRYXHiz1iK503fS-K2FZo-Ublwwa2xFZWpsUU_jtoVCwIkaqZuo6xoKtlMYXXvfVHGuKBHEBVn8b8x_57BQWz1d0KdrNXxuMvtFe6RzMqiMqzqZrzae4UqVCkYqcR9gQx66Ehq7hPmCxJCkg7ajo7fu6E7dPd34KH2HSYRsaaEA_BcKTeb9H1XE_qEKjog68wUU9Ekfl3FBIRN-1Ah_BoktGFoXyi_jt0-L0-gKcL1BLmUlGzMusvRbjI_0-qj-mc0utGdRjY-xIN2yBj8vl4DODO-wMwfp-cqZbCd9TENyHaTb8iA27s-73L3ExOQ"
}
},
{
kid: "IdTokenSigningKeyContainer.v3",
nbf: 1459289287,
use: "",
lbalmaceda marked this conversation as resolved.
Show resolved Hide resolved
kty: "RSA",
e: "AQAB",
n:
"s4W7xjkQZP3OwG7PfRgcYKn8eRYXHiz1iK503fS-K2FZo-Ublwwa2xFZWpsUU_jtoVCwIkaqZuo6xoKtlMYXXvfVHGuKBHEBVn8b8x_57BQWz1d0KdrNXxuMvtFe6RzMqiMqzqZrzae4UqVCkYqcR9gQx66Ehq7hPmCxJCkg7ajo7fu6E7dPd34KH2HSYRsaaEA_BcKTeb9H1XE_qEKjog68wUU9Ekfl3FBIRN-1Ah_BoktGFoXyi_jt0-L0-gKcL1BLmUlGzMusvRbjI_0-qj-mc0utGdRjY-xIN2yBj8vl4DODO-wMwfp-cqZbCd9TENyHaTb8iA27s-73L3ExOQ"
},
{
kid: "IdTokenSigningKeyContainer.v3",
lbalmaceda marked this conversation as resolved.
Show resolved Hide resolved
nbf: 1459289287,
use: "enc",
kty: "RSA",
e: "AQAB",
n:
"s4W7xjkQZP3OwG7PfRgcYKn8eRYXHiz1iK503fS-K2FZo-Ublwwa2xFZWpsUU_jtoVCwIkaqZuo6xoKtlMYXXvfVHGuKBHEBVn8b8x_57BQWz1d0KdrNXxuMvtFe6RzMqiMqzqZrzae4UqVCkYqcR9gQx66Ehq7hPmCxJCkg7ajo7fu6E7dPd34KH2HSYRsaaEA_BcKTeb9H1XE_qEKjog68wUU9Ekfl3FBIRN-1Ah_BoktGFoXyi_jt0-L0-gKcL1BLmUlGzMusvRbjI_0-qj-mc0utGdRjY-xIN2yBj8vl4DODO-wMwfp-cqZbCd9TENyHaTb8iA27s-73L3ExOQ"
},
]
});

Expand All @@ -289,12 +307,13 @@ describe("JwksClient", () => {
client.getSigningKeys((err, keys) => {
expect(err).to.be.null;
expect(keys).not.to.be.null;
expect(keys.length).to.equal(2);
expect(keys.length).to.equal(3);
expect(keys[0].rsaPublicKey).not.to.be.null;
expect(keys[0].kid).to.equal("IdTokenSigningKeyContainer");
expect(keys[1].kid).to.equal("IdTokenSigningKeyContainer.v2");
expect(keys[1].rsaPublicKey).not.to.be.null;
expect(keys[1].nbf).to.equal(1459289287);
expect(keys[2].rsaPublicKey).not.to.be.null;
done();
});
});
Expand Down