I was able to create user in Keycloak by posting a json containing only 1 user using postman.
http://localhost:8080/auth/admin/realms/master/users
But when i tried to create more than 1 user by passing a json array of more than 1 record i am getting a 500 Internal server error
[
{
"username": "user1",
"firstName": "John",
"attributes": {
"pl_uid": null
},
"credentials": [
{
"temporary": true,
"type": "password",
"value": "ares2012"
}
]
},
{
"username": "1000195",
"firstName": "Matt",
"attributes": {
"pl_uid": null
},
"credentials": [
{
"temporary": true,
"type": "password",
"value": "rx3o0t9f"
}
]
}
]
Is there any way by which we can send a json array to keycloak and create users there?
And then you can create a user like this: Keycloak keycloak = Keycloak. getInstance("http://localhost:8080/auth", "master", "admin", "admin", "admin-cli", "password"); UserRepresentation user = new UserRepresentation(); user. setUsername("username1"); user.
Get users. Default number of users is 100. Parameters max and first allow to paginate and retrieve more than 100 users.
user federation provider. Keycloak can store and manage users. Often, companies already have LDAP or Active Directory services that store user and credential information. You can point Keycloak to validate credentials from those external stores and pull in identity information. identity provider.
You need first to obtain an access token from Master realm and then using this access token submit a request to realm you want to get users from. Make sure to use "client_id=admin-cli" parameter when requesting the access token from Master realm.
Please have a look on the discussion added in Keycloak mailing list
Just double checked the approach I suggested. I thought we had made it possible to import users into an existing realm, but that's not the case. You have to create the whole realm. It's still possible to do it this way, first create the realm and add an example user. Stop the server and run it again with:
bin/standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=dir -Dkeycloak.migration.realmName=<realm name> -Dkeycloak.migration.dir=<dir name>
- Replace realm name and dir name
In dir name you should then get a few json files. You can then update realm name-users-0.json to add the users you want to import.
As Bill points out the admin client could be a good alternative approach. We also have a Java client that makes it simpler to use. Have a look at the admin-client example.
So this URL can help. Have a look at this link
Another option is using partialImport API for importing users (use admin user token):
access_token=`curl --data "grant_type=password&username=admin&password=admin&client_secret=secret&client_id=admin-cli" http://localhost:8180/auth/realms/master/protocol/openid-connect/token| jq -r .access_token`
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" --data "@$PWD/myrealm-users-0.json" http://localhost:8180/auth/admin/realms/myrealm/partialImport
After checking Keycloak's REST API doesn't look like bulk/batch requests for creating users are accepted. The only solution would be to send the POST
request for every user.
This is not surprising, HTTP is not prepared for this kind of requests:
As HTTP does not provide proper guidance for handling batch/bulk requests and responses.
from this RESTful guide. Have a look to it, it's really usefull in REST devlopments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With