'invalid keycloak jwt token signature


private void verifySignature(DecodedJWT decodedJWT)
{
    JsonObject payloadAsJson = decodeTokenPayloadToJsonObject(decodedJWT);
    String iss=payloadAsJson.get("iss").getAsString();
    System.out.println("iss"+iss);
    JwkProvider provider = new UrlJwkProvider(iss);//+"/protocol/openid-connect/certs");
    System.out.println("provider"+provider);
    Jwk jwk = provider.get(decodedJWT.getKeyId());
    System.out.println("jwk"+jwk);
    Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null);
    algorithm.verify(decodedJWT);
}

as you can see, I'm trying to validate the token signature using above method but it shows me below error

com.auth0.jwk.NetworkException: Cannot obtain jwks from url https://{keycloak url}/auth/realms/CMMC5/.well-known/jwks.json



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source