Warm tip: This article is reproduced from serverfault.com, please click

其他-无法使用Keycloak REST API创建角色

(其他 - Can't create Role using Keycloak REST API)

发布于 2020-07-10 06:00:56

我正在尝试在Keycloak的领域中添加角色,但这给了我错误的请求响应。我的步骤:

  1. 使用以下方法获取令牌:
 curl -X POST "http://localhost:8180/auth/realms/master/protocol/openid-connect/token" \                                                                 
 -H 'Content-Type: application/x-www-form-urlencoded' \
 -d 'username=admin&password=admin&grant_type=password&client_id=admin-cli'
  1. 使用以下方法获取客户端ID:
curl -X GET http://localhost:8180/auth/admin/realms/my-realm/clients?clientId=my-client \
 -H "Authorization: Bearer "$access_token \
 -H 'cache-control: no-cache'
  1. 尝试使用[documentation] [1]添加角色:
curl -v http://localhost:8180/auth/admin/realms/my-realm/clients/[ID-from-above]/roles \
 -H "Content-Type: application.json" \
 -H "Authorization: Bearer "$access_token --data '{"name":"test-role"}'

当我发出最后一条命令时,我得到了错误的请求响应。我究竟做错了什么?谢谢你。

https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_roles_resource

Questioner
Dula
Viewed
0
tryingToLearn 2020-07-16 11:23:22

你似乎很接近。

我可以通过遵循REST API来创建领域级别的角色:

在此处输入图片说明

此呼叫与你的呼叫之间的区别在于,你想充当客户端级别的角色。你是否对客户端级别角色有特定要求,或者你只是在尝试?

如果领域级别的角色满足你的要求,则可以使用上述API。

另请检查此帖子,以确保你已正确按照步骤进行操作,以设置admin Rest API。