目前,我尝试通过 Keycloak 的 Admin REST API 从curl 命令创建用户。
我可以将自己验证为管理员,我有一个很好的答案,但是当我想创建用户时,出现类似以下错误:“404 - 未找到”。
这是我的curl命令:
#!/bin/bash
echo "* Request for authorization"
RESULT=`curl --data "username=pierre&password=pierre&grant_type=password&client_id=admin-cli" http://localhost:8080/auth/realms/master/protocol/openid-connect/token`
echo "\n"
echo "* Recovery of the token"
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
echo "\n"
echo "* Display token"
echo $TOKEN
echo "\n"
echo " * user creation\n"
curl http://localhost:8080/apiv2/users -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"[email protected]", "enabled":"true"}'
我使用了官方API文档,位于这个地址:https://www.keycloak.org/docs-api/4.4/rest-api/index.html
I have this error:
my realm is good
我该如何修复它?
提前致谢。
试试这个,我添加了内容类型标头并修改了网址:
#!/bin/bash
echo "* Request for authorization"
RESULT=`curl --data "username=admin&password=Pa55w0rd&grant_type=password&client_id=admin-cli" http://localhost:8080/auth/realms/master/protocol/openid-connect/token`
echo "\n"
echo "* Recovery of the token"
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
echo "\n"
echo "* Display token"
echo $TOKEN
echo "\n"
echo " * user creation\n"
curl -v http://localhost:8080/auth/admin/realms/apiv2/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"[email protected]", "enabled":"true"}'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)