gpt4 book ai didi

keycloak - 如何在没有管理员帐户的情况下通过 REST 获取 Keycloak 用户

转载 作者:行者123 更新时间:2023-12-02 15:06:02 25 4
gpt4 key购买 nike

有没有办法使用管理员帐户通过 REST 获取 Keycloak 领域的用户列表?也许可以从管理控制台分配某种角色?寻找任何想法。

现在,我正在使用管理员凭据来获取访问 token ,然后使用该 token 从 realm/users 端点提取用户。

获取 token (通过请求从node.js应用程序):

uri: `${keycloakUri}/realms/master/protocol/openid-connect/token`,
form: {
grant_type: 'password',
client_id: 'admin-cli',
username: adminUsername,
password: adminPassword,
}

使用 token :

uri: `${keycloakUri}/admin/realms/${keycloakRealm}/users`,
headers: {
'authorization': `bearer ${passwordGrantToken}`,
}

我希望能够使用客户端应用程序中的通用用户信息(用户名、电子邮件、全名)。

最佳答案

您需要从 realm-management 客户端为所需用户分配 view-users 角色。这将是用户的配置:

enter image description here

然后您可以从 ${keycloakUri}/admin/realms/${keycloakRealm}/users 端点获取所有用户。这是从 enpoint 检索的信息,通过 Postman 访问:

enter image description here

此外,与所提出的问题无关,我强烈建议您不要使用 grant_type=password ,除非您绝对需要。来自 keycloak blog :

RESULT=`curl --data "grant_type=password&client_id=curl&username=user&password=password" http://localhost:8180/auth/realms/master/protocol/openid-connect/token`

This is a bit cryptic and luckily this is not how you should really be obtaining tokens. Tokens should be obtained by web applications by redirecting to the Keycloak login page. We're only doing this so we can test the service as we don't have an application that can invoke the service yet. Basically what we are doing here is invoking Keycloaks OpenID Connect token endpoint with grant type set to password which is the Resource Owner Credentials flow that allows swapping a username and a password for a token.

另请参阅Oauth2 spec .

关于keycloak - 如何在没有管理员帐户的情况下通过 REST 获取 Keycloak 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46470477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com