How to verify keyckloak id_token?
I have client jwt token from Keycloak (id_token)
I need verify it.
With head { "alg": "RS256", "typ": "JWT", "kid": "some kid" }
I obtain publick_key from
https://{somehost}/auth/realms/{somerealm}
When you have publick_key and id_token(jwt)
You can verify token.
But I can't
I try
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(publickKeyStr);
KeyFactory kf = KeyFactory.getInstance("RSA")
PulblickKey publickKey = kf.generatePublick(keySpec);
Then
try {
Claims claims = Jwts.parserBuilder()
.setSigningKey(publickKey).build().parseClaimsJws(idToken).getBody();
} catch {io.jsonwebtoken.security.SecurityException | MalformedJwtException e) {
log.info("Invalid Keycloak JWT signature");
}
Then I have error Invalid Keycloak JWT signature