java-jwt icon indicating copy to clipboard operation
java-jwt copied to clipboard

Validate against multiple issuers

Open cescoferraro opened this issue 8 years ago • 11 comments

Is there a way to validate against multiple issuers with the current api?

cescoferraro avatar Mar 09 '18 15:03 cescoferraro

No, since the JWTVerifier#withIssuer only accepts a single string and the JWTVerifier#withArrayClaim will check that all the passed array contents are present in the token rather than only checking if the token's issuer is part of the passed array. Could be added though.

lbalmaceda avatar Mar 09 '18 16:03 lbalmaceda

Other JWT libraries accept an array of issuers so this would be a very nice-to-have.

chrisolson443 avatar Jun 04 '18 22:06 chrisolson443

We are looking for something similar when switching to a custom domain with auth0, when you switch to a custom domain the issuer changes although the auth0 tenant stays the same. To handle this we temporarily have to accept multiple issuers.

The patch with having multiple verifiers seems to be the best solution to be able to transition properly.

jogee avatar Jul 18 '18 08:07 jogee

This is already in our backlog. I'll discuss with the team on the coming days if we should raise the priority. 👍

lbalmaceda avatar Jul 18 '18 15:07 lbalmaceda

I'd like to have this too. My use case is that we have one issuer prefix e.g. https://foo.com with multiple valid paths, such as https://foo.com/v1-issuer and https://foo.com/v2-issuer. Therefore, I need to be able to pass in a list of valid issuers.

You could make this even more generic by supporting a method like withIssuer(IssuerValidator) where IssuerValidator is a SAM interface for easy lamda implementation. That being said, more complex cases like that can be handled at the application level after parsing, so I would be fine with just the multiple issuer support.

rocketraman avatar Oct 14 '18 15:10 rocketraman

That being said, more complex cases like that can be handled at the application level after parsing, so I would be fine with just the multiple issuer support.

Enabling this at the application level would be nice by supporting a generic validation method like this on Verification, where each call contributes an additional custom validation:

withCustomValidation(CustomJwtValidator) where CustomJwtValidator is:

interface CustomJwtValidator {
  validate(DecodedJWT jwt) throws JWTVerificationException;
}

rocketraman avatar Oct 14 '18 15:10 rocketraman

FYI, the logic I describe above implemented in https://github.com/auth0/java-jwt/pull/290.

rocketraman avatar Oct 17 '18 04:10 rocketraman

With the custom validator the issuer claim would still fail if multiple issuers aren't supported, these look like two separate concepts. Adding the possibility to add custom validations on application layer seems like a good idea though.

jogee avatar Oct 17 '18 08:10 jogee

With the custom validator the issuer claim would still fail if multiple issuers aren't supported, these look like two separate concepts. Adding the possibility to add custom validations on application layer seems like a good idea though.

I agree, the custom validation logic is not a replacement for this issue -- I do believe it is still a valid thing to desire the ability to validate against multiple issuers. I simply reference it as a workaround that is also useful in other situations.

rocketraman avatar Oct 17 '18 14:10 rocketraman

This issue is solved with https://github.com/auth0/java-jwt/pull/288, is it not?

coperator avatar Jun 19 '19 09:06 coperator

Yes, it can be closed.

jogee avatar Jun 19 '19 09:06 jogee