1

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

  • Did you check if you really get a KeyId (`kid`), if that endpoint is reachable and if there is a key with a matching kid on this endpoint? – jps Feb 18 '22 at 18:21
  • @jps I am getting kid using this line decodedJWT.getKeyId() and even check kid present or not using this url https://{keycloak url}/auth/realms/CMMC5/protocol/openid-connect/certs/ but still I'm getting error com.auth0.jwk.NetworkException: Cannot obtain jwks from url https://{keycloak url}/auth/realms/CMMC5//protocol/openid-connect/certs/.well-known/jwks.json – nitanshu sharma Feb 19 '22 at 17:22

0 Answers0