-
Notifications
You must be signed in to change notification settings - Fork 937
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 ability to verify audience contains at least one of those expected #472
Conversation
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.
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
private void verifyClaimValues(DecodedJWT jwt, Map.Entry<String, Object> entry) { | |
switch (entry.getKey()) { | |
case PublicClaims.AUDIENCE: | |
assertValidAudienceClaim(jwt.getAudience(), (List<String>) entry.getValue()); | |
break; | |
case PublicClaims.EXPIRES_AT: |
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,
withAudience
requires 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:
withAudience
andwithAnyOfAudience
are called on the sameVerification
instance, anIllegalStateException
will be thrown.Alternatives considered:
withAudience
andwithAnyOfAudience
are used on the sameVerification
instance, 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