我使用AuthzClient使用下面的代码来获取访问令牌。
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());
我成功地获取了访问令牌和刷新令牌 但我无法获取其他的请求。它是空的。
我已经配置了Mapper来包含我的来自portal的自定义属性。我在这里做错了什么?
我没有找到任何关于keycloak authzclient的解决方案。但我使用jwt解码方案作为。https:/github.comauth0java-jwt。
我的例子就像这样用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()