Bash keydove,通过curl上的管理api向用户添加领域角色

Bash keydove,通过curl上的管理api向用户添加领域角色,bash,Bash,使用KeyClope 6.0.1 我已经创建了领域角色和用户。我有用户uuid和角色uuid 如果我跑 curl -v -X POST -w "\n" http://localhost:8080/auth/admin/realms/SpringBootKeycloak/users/$USER_ID/role-mappings/realm -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '[{

使用KeyClope 6.0.1

我已经创建了领域角色和用户。我有用户uuid和角色uuid

如果我跑

curl -v -X POST -w "\n" http://localhost:8080/auth/admin/realms/SpringBootKeycloak/users/$USER_ID/role-mappings/realm -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '[{"id":$ROLE_ID,"name":"user"}]'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /auth/admin/realms/SpringBootKeycloak/users/fe38bcb5-258b-44e4-a056-cf8c1a29b99f/role-mappings/realm HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Type: application/json
> Authorization: bearer very long string
> Content-Length: 31
> 
* upload completely sent off: 31 out of 31 bytes
< HTTP/1.1 500 Internal Server Error
< Connection: keep-alive
< Content-Length: 0
< Date: Fri, 13 Sep 2019 08:53:14 GMT
< 
* Connection #0 to host localhost left intact
或者,如果我使用的数据运行curl

--数据'[{“id”:“$ROLE_id”,“name”:“user”}]'

然后返回404未找到

如果我将数据设置为硬编码,那么它会工作

--数据'[{“id”:“9b6371f2-646d-4927-b3b6-6e208935517e”,“名称”:“用户”}]

但获得204无内容的回报是成功的。并添加了角色

进一步调查-

--数据'[{“id”:“$ROLE_id'”,“name”:“user”}]'

提供204状态,并将角色添加到用户


所以,最终还是要做到这一点。

这是变量替换的问题:

$ export ROLE_ID=9b6371f2-646d-4927-b3b6-6e208935517e
$ echo '[{"id":"'$ROLE_ID'","name":"user"}]'
[{"id":"9b6371f2-646d-4927-b3b6-6e208935517e","name":"user"}]
$ echo '[{"id":$ROLE_ID,"name":"user"}]'
[{"id":$ROLE_ID,"name":"user"}]
$ echo '[{"id":"$ROLE_ID","name":"user"}]'
[{"id":"$ROLE_ID","name":"user"}]

$ export ROLE_ID=9b6371f2-646d-4927-b3b6-6e208935517e
$ echo '[{"id":"'$ROLE_ID'","name":"user"}]'
[{"id":"9b6371f2-646d-4927-b3b6-6e208935517e","name":"user"}]
$ echo '[{"id":$ROLE_ID,"name":"user"}]'
[{"id":$ROLE_ID,"name":"user"}]
$ echo '[{"id":"$ROLE_ID","name":"user"}]'
[{"id":"$ROLE_ID","name":"user"}]