what is the alternative for deprecated method org.keycloak.TokenVerifier.realmUrl()

1.1k views Asked by At

I am trying to verify the AccessToken using below code -

TokenVerifier verifier = TokenVerifier.create(StringAccessToken, AccessToken.class).withDefaultChecks(); PublicKey publicKey = getRealmPublicKey(verifier.getHeader()); return verifier.realmUrl(“someStringUrl”).publicKey(publicKey).verify().getToken();

But seems a realmUrl() method is deprecated. Can you please help with alternative solution for this?

or can you suggest an effective way to verify access token ?

1

There are 1 answers

1
Ganesh Dhongade On

We can use org.keycloak.TokenVerifier#withChecks which takes predicates for token validation. The realm check is performed by org.keycloak.TokenVerifier.RealmUrlCheck

The modified code would be:

TokenVerifier<AccessToken> verifier = TokenVerifier.create(token, AccessToken.class).withChecks(new TokenVerifier.RealmUrlCheck(getRealmUrl()));
PublicKey publicKey = getRealmPublicKey(verifier.getHeader());
return verifier.publicKey(publicKey).verify().getToken();