Support JWKS with multiple algorithms

Issue #353 resolved
Former user created an issue

An auth provider that I am currently integrating with serves a JWKS with jumbled signing algorithms. For example, the well-known endpoint will have keys that use RS256, EC256 etc. The current JWSVerificationKeySelector only supports a single algorithm. My questions as follows:

  • Is there already a class that supports this scenario and I simply haven't seen it (very possible)
  • If not, can I raise a PR that implements this?

I have already implemented the JWSVerificationMultiKeySelector in our code base, but would love to contribute this back to your project (with all relevant tests of course!) if you don't have such a thing.

Comments (10)

  1. Marco Vermeulen

    Hi Vladimir, unfortunately using an ImmutableJWKSet doesn't work for me as we depend on a wellknown JWKS endpoint for serving the keys (with jumbled algorithms). What makes it more tricky is that they do regular key rotation.

    I’d love to contribute a PR for the work that I did if you are open to it.

    Cheers,

    Marco.

  2. Marco Vermeulen

    Yes, and I’m using it too. Here is how I implemented the JWT processor using my new key selector implementation.

    private val jwtProcessor by lazy {
            DefaultJWTProcessor<SecurityContext>().apply {
                jwsTypeVerifier = DefaultJOSEObjectTypeVerifier(
                    JOSEObjectType("ciam+jwt")
                )
                jwsKeySelector = JWSVerificationMultiKeySelector(
                    listOf(ES256, ES384, ES512, HS256, HS384, HS512, RS256, RS384, RS512),
                    RemoteJWKSet(URL(ciamJwksEndpoint))
                )
                jwtClaimsSetVerifier = DefaultJWTClaimsVerifier(
                    JWTClaimsSet.Builder()
                        .issuer(issuerClaim)
                        .audience(audienceClaim)
                        .claim("scope", scope)
                        .build(),
                    setOf("sub", "iss", "aud", "jti", "iat", "exp")
                )
            }
        }
    

    Hope that with the example it makes more sense now 🙂

  3. Marco Vermeulen

    Yes, that was my first approach too, but then ran into that limitation. PR for JWSVerificationMultiKeySelector and corresponding test(s) coming up.

  4. Log in to comment