Skip to content

Optional kid on single item JWK sets#32

Merged
lbalmaceda merged 3 commits intomasterfrom
optional-kid
Jul 18, 2018
Merged

Optional kid on single item JWK sets#32
lbalmaceda merged 3 commits intomasterfrom
optional-kid

Conversation

@lbalmaceda
Copy link
Copy Markdown
Contributor

@lbalmaceda lbalmaceda commented Jul 16, 2018

As per https://tools.ietf.org/html/rfc7517#section-4.4 the kid is optional. This PR allows to obtain a key from a single item array without passing the key id value.

This doesn't break cached provider implementation as a valid key string is still used to store the jwk obtained when passing null as parameter to the get(kid) call.

Closes #23

@lbalmaceda lbalmaceda changed the title Optional kid on single item sets As per https://tools.ietf.org/html/rfc7517#section-4.4 the kid is optional. This PR allows to obtain a key from a single item array without passing the key id value. Optional kid on single item JWK sets Jul 16, 2018
Copy link
Copy Markdown
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly straight forward and a lot of this is formatting but a few questions on the meat of the implementation.

}
}
}
throw new SigningKeyNotFoundException("No key found in " + url.toString() + " with kid " + keyId, null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this message still be clear if keyId is null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,null gets converted to "null" (string). Still clear that the value is missing, that's what null means anyway for us in Java.

"No key found in https://joshcanhelp.auth0.com/.well-known/jwks.json with kid null"

if (keyId.equals(jwk.getId())) {
return jwk;
if (keyId == null && jwks.size() == 1) {
return jwks.get(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a work-around if jwks.size() > 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean keyid==null and jwks.size()>1 ?? no. Since there are many keys to choose from and the user hasn't passed a key id to filter them. This was the previous behavior: throw if key id not found in the set.

}
if (keyId != null) {
for (Jwk jwk : jwks) {
if (keyId.equals(jwk.getId())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that this portion of the method takes into account multiple entries in the JWKs but the previous one does not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's only filtering the entries in a list for those which match a given key id. see:

  • if key is specified, match by key even if set size is 1, since the user wants that key.
  • if key is not specified and size is 1 the solution is trivial -> return that item
  • in any other case, throw key with id "{id}" not found.

Copy link
Copy Markdown
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbalmaceda - I was mis-reading what that JWKS check was supposed to do ... read it as looking through multiple JWKSes.

LGTM 👍

@lbalmaceda lbalmaceda merged commit 0347051 into master Jul 18, 2018
@lbalmaceda lbalmaceda deleted the optional-kid branch July 18, 2018 17:45
@lbalmaceda lbalmaceda modified the milestones: v0-Next, 0.6.0 Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants