如何在 keycloak Admin API 中使用用户数据获取领域角色

Vig*_*das 3 javascript node.js keycloak keycloak-services

API:POST /{领域}/用户

根据文档,他们指定领域角色存在,但在调用 API 时不会将其添加到用户数据中。

Lac*_*lev 5

我猜你的意思是GET,不是吗POST?但这并不重要。

实际上,返回的UserRepresentation-s 仅包含所有已记录属性的子集,并且领域角色不属于该子集。该文档对这个“小”细节只字未提,这似乎是造成混乱的根源。你可以看这里

您可以使用auth/admin/realms/{realm}/users/{user-uuid}/role-mappings/realm来获取角色。例如:

  curl \
    -H "Authorization: bearer ...." \
    "http://localhost:8080/auth/admin/realms/<realm-here>/users/<user-id-here>/role-mappings/realm"
Run Code Online (Sandbox Code Playgroud)

回复:

[
   {
      "id":"dcc58028-ba8a-4545-bafe-e8004488e4c5",
      "name":"admin",
      "description":"${role_admin}",
      "composite":true,
      "clientRole":false,
      "containerId":"master"
   },
   {
      "id":"99f5bb44-c203-493f-9eaa-6ec3a8ff264a",
      "name":"uma_authorization",
      "description":"${role_uma_authorization}",
      "composite":false,
      "clientRole":false,
      "containerId":"master"
   },
   {
      "id":"51853542-2ee8-4b29-b05c-03ef86f5b333",
      "name":"offline_access",
      "description":"${role_offline-access}",
      "composite":false,
      "clientRole":false,
      "containerId":"master"
   }
]
Run Code Online (Sandbox Code Playgroud)