通过curl命令在Keycloack上创建用户

编程入门 行业动态 更新时间:2024-10-09 17:22:22
本文介绍了通过curl命令在Keycloack上创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当前,我尝试通过Keycloak的Admin REST API从curl命令创建用户. 我可以以管理员身份进行身份验证,我的回答很好,但是当我要创建用户时,会出现类似"404-Not Found"的错误.

Currently I try to create a user from curl command via Keycloak's Admin REST API. I can authenticate myself as an admin, I have a good answer, but when I want to create a user, I have an error like: "404 - Not Found".

这是我的curl命令:

Here are my curl commands:

#!/bin/bash echo "* Request for authorization" RESULT=`curl --data "username=pierre&password=pierre&grant_type=password&client_id=admin-cli" 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 localhost:8080/apiv2/users -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"demo2@gmail", "enabled":"true"}'

我使用了位于以下地址的官方API文档: www.keycloak/docs-api/4.4/rest-api/index.html

I used the official API documentation, located at this address: www.keycloak/docs-api/4.4/rest-api/index.html

我有此错误:

我的境界很好

我该如何解决? 预先感谢.

How I can fix it? Thanks in advance.

推荐答案

尝试一下,我添加了内容类型标头并修改了url:

try this, I added the content type header and modify the url :

#!/bin/bash echo "* Request for authorization" RESULT=`curl --data "username=admin&password=Pa55w0rd&grant_type=password&client_id=admin-cli" 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 localhost:8080/auth/admin/realms/apiv2/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"demo2@gmail", "enabled":"true"}'

更多推荐

通过curl命令在Keycloack上创建用户

本文发布于:2023-11-28 11:52:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   用户   curl   Keycloack

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!