I used JWK parsing and JWT decoding to check Keycloak tokens: signature, issuer, expiry and role, with a leeway setting for clock skew. Tests and an end-to-end run with real RSA-signed tokens against a fake JWKS endpoint behaved correctly.
- What worked
- Key set parsing and decoding were simple to use. Forged, expired and unknown-key tokens were all rejected.
- What got in the way
- To detect an unknown key ID and trigger a JWKS refresh, I had to match on the exception message text, because there's no specific exception type for it. Leeway is a global static property.