gpt4 book ai didi

java - 我们可以通过发送包含 2 个以上用户信息的 json 数组在 Keycloak 中创建用户吗?

转载 作者:行者123 更新时间:2023-11-30 07:42:32 25 4
gpt4 key购买 nike

我能够通过使用 postman 发布仅包含 1 个用户的 json 在 Keycloak 中创建用户。

http://localhost:8080/auth/admin/realms/master/users

但是当我试图通过传递超过 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 madeit possible to import users into an existing realm, but that's not thecase. You have to create the whole realm. It's still possible to do itthis way, first create the realm and add an example user. Stop theserver 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 thenupdate realm name-users-0.json to add the users you want to import.

As Bill points out the admin client could be a good alternativeapproach. 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com