-
Notifications
You must be signed in to change notification settings - Fork 925
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
Add support for passing json values for header and payload #643
Merged
jimmyjames
merged 10 commits into
auth0:master
from
andrewrigas:allow-json-string-claims
Mar 27, 2023
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
78a10b3
Add support for passing json values for header and payload
andrewrigas 186df4d
rename functions
andrewrigas a95382d
remove extra space
andrewrigas d171fbc
formated
andrewrigas 3a531a3
add documentation
andrewrigas 8c3f5c7
remove extra space
andrewrigas a7b5f19
Merge branch 'master' into allow-json-string-claims
andrewrigas dbc90eb
reorder params
andrewrigas f1dcc62
resolve comments
andrewrigas 6233867
update tests to include error case
andrewrigas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,24 @@ public Builder withHeader(Map<String, Object> headerClaims) { | |
return this; | ||
} | ||
|
||
/** | ||
* Add specific Claims to set as the Header. | ||
* If provided json is null then nothing is changed | ||
* | ||
* @param headerClaimsJson the values to use as Claims in the token's Header. | ||
* @return this same Builder instance. | ||
* @throws JsonProcessingException if json value has invalid structure | ||
*/ | ||
public Builder withHeader(String headerClaimsJson) throws JsonProcessingException { | ||
if (headerClaimsJson == null) { | ||
return this; | ||
} | ||
|
||
Map<String, Object> headerClaims = mapper.readValue(headerClaimsJson, HashMap.class); | ||
|
||
return withHeader(headerClaims); | ||
} | ||
|
||
/** | ||
* Add a specific Key Id ("kid") claim to the Header. | ||
* If the {@link Algorithm} used to sign this token was instantiated with a KeyProvider, | ||
|
@@ -467,6 +485,30 @@ public Builder withPayload(Map<String, ?> payloadClaims) throws IllegalArgumentE | |
return this; | ||
} | ||
|
||
/** | ||
* Add specific Claims to set as the Payload. If the provided json is null then | ||
* nothing is changed. | ||
* | ||
* <p> | ||
* If any of the claims are invalid, none will be added. | ||
* </p> | ||
* | ||
* @param payloadClaimsJson the values to use as Claims in the token's payload. | ||
* @return this same Builder instance. | ||
* @throws IllegalArgumentException if any of the claim keys or null, | ||
* or if the values are not of a supported type. | ||
* @throws JsonProcessingException if json value has invalid structure | ||
*/ | ||
public Builder withPayload(String payloadClaimsJson) throws IllegalArgumentException, JsonProcessingException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here re. the jackson exception. |
||
if (payloadClaimsJson == null) { | ||
return this; | ||
} | ||
|
||
Map<String, Object> payloadClaims = mapper.readValue(payloadClaimsJson, HashMap.class); | ||
|
||
return withPayload(payloadClaims); | ||
} | ||
|
||
private boolean validatePayload(Map<String, ?> payload) { | ||
for (Map.Entry<String, ?> entry : payload.entrySet()) { | ||
String key = entry.getKey(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of throwing an exception from jackson, let's catch and throw an
IllegalArgumentException
with the nested cause, to be consistent with the other methods and not leak the jackson dependency.