Skip to content

Feature/#445 - withPayload(Map<String, Object> payloadClaims) method#454

Closed
onmax wants to merge 8 commits intoauth0:perform-releasefrom
onmax:feature/#445
Closed

Feature/#445 - withPayload(Map<String, Object> payloadClaims) method#454
onmax wants to merge 8 commits intoauth0:perform-releasefrom
onmax:feature/#445

Conversation

@onmax
Copy link
Copy Markdown

@onmax onmax commented Nov 7, 2020

Changes

Previously, you could initialize the Header of a JWT from a Map without any problem, but the story changed if you wanted to initialize a Payload, since you could not do it from a Map. The user had to add attributes one by one. With this new change, I added a new method withPayload(Map<String, Object> payloadClaims) in JWTCreator.java that allows to initialize the Payload from a Map.

References

Links supporting this change such as a:

Testing

Also, this new method has its own tests in the JWTCreatorTest.java.

  • This change adds test coverage
  • This change has been tested on the latest version of Java or why not

Checklist

@onmax onmax requested a review from a team November 7, 2020 01:29
@jimmyjames jimmyjames added CH: Added medium This PR may require moderate effort to action, or contains many changes to review labels Nov 10, 2020
@jimmyjames jimmyjames requested review from jimmyjames and removed request for a team November 10, 2020 14:48
Copy link
Copy Markdown
Contributor

@jimmyjames jimmyjames left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @onmax! In addition to the comment I left about ensuring we perform the same claim validation logic we currently have in this new method, can you remove the formatting changes to the src and test files (README is fine to leave)? Thanks!

}

return this;
}
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.

We should perform the same claim validations here as we do for others (key not null, values are supported types (should be able to use the isSupportedType() method).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure about that. But I can add isSupportedType(), I will check it later on

@onmax
Copy link
Copy Markdown
Author

onmax commented Nov 16, 2020

Yep, I will change it. Sorry, forgot I had the auto-format mode on, and didn't check my commit. My bad

@jimmyjames
Copy link
Copy Markdown
Contributor

@onmax feel free to push additional commits to this PR to address the requested changes. I'll be away next week, so will circle back the week of November 30.

@onmax
Copy link
Copy Markdown
Author

onmax commented Dec 8, 2020

Just updated the code with the requirements you asked. No auto-formatting.

@VictorNS69
Copy link
Copy Markdown

Hi, any news with this PR?

Copy link
Copy Markdown
Contributor

@jimmyjames jimmyjames left a comment

Choose a reason for hiding this comment

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

Generally looks good, but currently this does not compile and one of the tests needs updating to reflect the null handling for map claims.

If unable to follow-up with requested changes, we'll look at using this PR as a starting point and adding support for it as there does seem interest in this capability.

* @throws IllegalArgumentException if payloadClaims is not well-formed and not having null values
* @return this same Builder instance.
*/
public Builder withPayload(Map<?, ?> payloadClaims) throws IllegalArgumentException {
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.

Shouldn't this take a Map<String, Object>? As is, this does not compile (see build failure).

payload.put(PublicClaims.KEY_ID, null);
payload.put("test2", "isSet");

String signed = JWTCreator.init().withKeyId("test").withPayload(payload).sign(Algorithm.HMAC256("secret"));
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.

This test would fail as implemented, as the claim validation of map entries does not allow nulls. We probably want to maintain that consistency as currently implemented for lists and maps.

@jimmyjames
Copy link
Copy Markdown
Contributor

Using this PR as a starting point, I've made #475 to get this feature in. Thanks to @onmax and others for starting this and providing feedback. I encourage anyone interested to try and/or review the changes in #475, and provide any feedback there.

I'm closing this PR in favor of #475, I encourage anyone interested to try and/or review those changes and provide any feedback there.

@jimmyjames jimmyjames closed this Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CH: Added medium This PR may require moderate effort to action, or contains many changes to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants