Add ability to verify audience contains at least one of those expected#472
Add ability to verify audience contains at least one of those expected#472lbalmaceda merged 3 commits intomasterfrom
Conversation
lbalmaceda
left a comment
There was a problem hiding this comment.
I think we can avoid this flag if we reuse the existing Map<String, Object> claims. We could define a new constant for AUDIENCE_EXACT vs AUDIENCE_CONTAINS and then in the switch case pick the strategy.
java-jwt/lib/src/main/java/com/auth0/jwt/JWTVerifier.java
Lines 326 to 331 in 5afd80d
The only thing I'd be careful of is not exposing these two new constants, as they are rather used internally.
The flag would go away and we could even skip checking and throwing if a different audience verification strategy was already set, as both could now co-exist. Thoughts?
Yes, we could do that. It avoids adding another parameter to the
Can you think of a use case where both strategies would be used on the same verification? Or, we don't need to throw an exception if both are used, and instead could let the last one configured win. If using new custom claim keys to determine how the audience should be validated, we'd just remove the other claim from the expectations (e.g., |
We discussed offline, and will proceed to manage the expected audience values internally using different keys for the desired verification behavior. We will also update this PR such that if both |
006e653 to
8de8152
Compare
Changes
This PR adds the ability to verify that a JWT's audience claim contains at least one of the expected audiences. Currently,
withAudiencerequires that the audience claim match the specified audience exactly.Resolves #449
New public method:
withAnyOfAudience(String... audience)- verifies that the JWT's audience claim contains at least one of the specified audiences.Details:
withAudienceandwithAnyOfAudienceare called on the sameVerificationinstance, anIllegalStateExceptionwill be thrown.Alternatives considered:
withAudienceandwithAnyOfAudienceare used on the sameVerificationinstance, the last one called wins. We could document that behavior, but discussion with @lbalmaceda thought it best for us to throw in that scenario.Checklist