Reputation: 1605
I'm using AuthzClient to obtain a access token using the following code:
Map<String,Object> clientCredentials = new HashMap<>();
clientCredentials.put("secret", keycloakClientSecret);
Configuration configuration = new Configuration(
keycloakUrl, keycloakRealmName, keycloakClientId, clientCredentials, null
);
AuthzClient authzClient = AuthzClient.create(configuration);
AccessTokenResponse accessTokenResponse = authzClient.obtainAccessToken(
loginRequest.getUsername(), loginRequest.getPassword()
);
System.out.println(accessTokenResponse.getOtherClaims());
I'm getting the access token and refresh token successfully but I can't get the other claims. It's empty.
I've configured Mapper to include my custom attribute from portal. What I'm doing wrong here?
Upvotes: 1
Views: 1688
Reputation: 780
I didnt find any solution about keycloak authzclient. But i am using jwt decode solution as https://github.com/auth0/java-jwt
my example like this with jwt-decoder:
public Claim getClaimByName(String key)
{
try {
DecodedJWT jwt = JWT.decode(this.tokenResponse.getAccessToken()); // just token as String
return jwt.getClaim(key);
} catch (JWTCreationException exception){
return null;
}
}
getClaimByName("site").asString()
Upvotes: 1