![](/img/trans.png)
[英]How can I update keycloak's user details programmatically (java), without using rest admin api?
[英]How can I get a user's first, last name, and attribute from keycloak with the Java API?
我可以使用Java API代碼從給定用戶名和密碼的情況下從keycloak獲取令牌:
AccessTokenResponse tokenresponse = authzClient.obtainAccessToken(user, password);
如何從Keycloak獲取此用戶的名字,姓氏以及其他屬性? 如Id?
我使用的代碼只是從AccessToken
獲取信息。 這是從JAX-RS服務獲取的,但是您不清楚如何嘗試訪問它。 也許它仍然可以給您一些想法。
@Path("/something")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response aMethod(@Context SecurityContext securityContext) {
Principal principal = securityContext.getUserPrincipal();
KeycloakPrincipal<KeycloakSecurityContext> keycloakPrincipal = (KeycloakPrincipal<KeycloakSecurityContext>) principal;
AccessToken accessToken = keycloakPrincipal.getKeycloakSecurityContext().getToken();
// first name
accessToken.getGivenName()
// last name
accessToken.getFamilyName();
// email
accessToken.getEmail();
// roles
accessToken.getRealmAccess().getRoles();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.