我能够通过使用 postman 发布仅包含 1 个用户的 json 在 Keycloak 中创建用户。
但是当我试图通过传递超过 1 条记录的 json 数组来创建超过 1 个用户时,我收到 500 内部服务器错误
[
{
"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"
}
]
}
]
有什么方法可以将 json 数组发送到 keycloak 并在那里创建用户?
最佳答案
请查看Keycloak邮件列表中添加的讨论
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.
所以这个 URL 可以提供帮助。看看this link
另一种选择是使用 partialImport API 导入用户(使用管理员用户 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
关于java - 我们可以通过发送包含 2 个以上用户信息的 json 数组在 Keycloak 中创建用户吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54512217/