Reputation: 168
I am new in Keycloak, so my question is maybe little dummy. So the question is, can I create user in a realm (ie: ExpRealm) via API? If yes, how?
I tried that and...
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
and I got that:
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
Upvotes: 0
Views: 324
Reputation: 189
Yes, you can create a user by using the keycloak admin REST APIs. Here's the spec for it - https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_users_resource
So in your case, the endpoint will become like this - POST /auth/admin/ExpRealm/users
Before you trigger this, get the access token and pass it in the header as Bearer token.
Upvotes: 1