papi1992
papi1992

Reputation: 168

Keycloak: Create User in a certain real which name is ExpRealm

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

Answers (1)

raghav
raghav

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

Body should be the user json Payload

Before you trigger this, get the access token and pass it in the header as Bearer token.

Authentication Header

Upvotes: 1

Related Questions