嗨,我正在尝试使用 Keycloak API,但我不太了解它是如何工作的。我想获取一个领域的所有用户。因此,我首先使用此端点获取令牌:/realms/master/protocol/openid-connect/token在请求正文中使用此参数:
第一个问题是:我应该使用什么客户端?
然后我调用这个端点:/admin/realms/master/users使用授权标头中的令牌,但我得到一个 403 状态代码,我不明白为什么。
谢谢
小智 18
你需要两步
首先从主域的 admin-cli 客户端获取访问令牌
第二次使用访问令牌调用 admin rest api,将 Bearer 设置为 Authorization 标头中的前缀。
# get an access token
curl -X POST \
https://<HOST>/auth/realms/master/protocol/openid-connect/token \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'grant_type=password&username=<USERNAME>l&password=<PASSWORD>&client_id=admin-cli'
# get all users of gateway realm, use the token from above and use Bearer as prefix
curl -X GET \
https://<HOST>/auth/admin/realms/gateway/users \
-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkI...' \
-H 'cache-control: no-cache'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19968 次 |
| 最近记录: |