我是Keycloak的新手,所以我的问题也许是个小人物。所以问题是,我可以通过API在领域(即ExpRealm)中创建用户吗?如果是,怎么办?
我尝试过,然后...
curl --data "client_id"="admin-cli" --data "username"="admin" --data "password"="admin" --data "grant_type"="password" --request POST http://localhost:8080/auth/realms/master/protocol/openid-connect/token
curl --header "Authorization: Bearer token" --request POST --data "username"="someone" http://localhost:8080/auth/admin/ExpRealm/users -vv
我明白了:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /auth/admin/EDL/users HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer token
> Content-Length: 15
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 15 out of 15 bytes
< HTTP/1.1 404 Not Found
< Connection: keep-alive
< Content-Length: 0
< Date: Fri, 03 May 2019 07:49:28 GMT
<
* Connection #0 to host localhost left intact
答案 0 :(得分:1)
是的,您可以使用keycloak admin REST API创建用户。 这是它的规格- https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_users_resource
因此,在您的情况下,端点将变成这样- POST / auth / admin / ExpRealm / users
在触发此操作之前,获取访问令牌并将其作为承载令牌传递到标头中。