Keycloak 创建用户的keydape API返回403
正在尝试使用KeyClope作为身份提供者。我使用Keycloak 创建用户的keydape API返回403,keycloak,keycloak-services,keycloak-rest-api,Keycloak,Keycloak Services,Keycloak Rest Api,正在尝试使用KeyClope作为身份提供者。我使用/standalone.sh脚本运行它 因此,我获得access\u令牌如下: curl --request POST \ --url http://localhost:8080/auth/realms/master/protocol/openid-connect/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type
/standalone.sh
脚本运行它
因此,我获得access\u令牌
如下:
curl --request POST \
--url http://localhost:8080/auth/realms/master/protocol/openid-connect/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=admin-cli \
--data client_secret=<the-client-secret-under-master-realm-for-admin-cli-client>
然后很快,在我的测试领域下
我尝试创建一个用户,如下所示:
curl --request POST \
--url http://localhost:8080/auth/admin/realms/test-realm/users \
--header 'Authorization: Bearer the-access-token' \
--header 'Content-Type: application/json' \
--data '{
"firstName": "Sergey",
"lastName": "Kargopolov",
"email": "test@test.com",
"enabled": "true",
"username": "app-user"
}'
TOKEN=$(curl -k -sS -d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password" \
http://$KEYCLOAK_IP/auth/realms/master/protocol/openid-connect/token)
curl -k -sS -X POST https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "$USER_JSON_DATA"
我被一个403
击中:
< HTTP/1.1 403 Forbidden
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Referrer-Policy: no-referrer
< Date: Thu, 28 Jan 2021 23:43:57 GMT
< Connection: keep-alive
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Content-Type-Options: nosniff
< Content-Type: application/json
< Content-Length: 25
有什么我遗漏的吗?我在跟踪,我做的每件事都和描述的一模一样
编辑:我尝试了密码授予的方式来获得承载令牌,这是有效的,但不是客户端秘密方式。显然,我更喜欢客户保密的方式(这就是我目前所处的困境)。这里可能存在什么问题?要使用KeyClope Rest API创建用户,只需通过提供管理员用户的名称和密码,从管理员cli客户端请求代表管理员用户的令牌,例如:
curl --request POST \
--url http://localhost:8080/auth/admin/realms/test-realm/users \
--header 'Authorization: Bearer the-access-token' \
--header 'Content-Type: application/json' \
--data '{
"firstName": "Sergey",
"lastName": "Kargopolov",
"email": "test@test.com",
"enabled": "true",
"username": "app-user"
}'
TOKEN=$(curl -k -sS -d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password" \
http://$KEYCLOAK_IP/auth/realms/master/protocol/openid-connect/token)
curl -k -sS -X POST https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "$USER_JSON_DATA"
从$TOKEN对象中提取访问令牌(我们将其命名为$access\u TOKEN
)
然后按如下方式创建用户:
curl --request POST \
--url http://localhost:8080/auth/admin/realms/test-realm/users \
--header 'Authorization: Bearer the-access-token' \
--header 'Content-Type: application/json' \
--data '{
"firstName": "Sergey",
"lastName": "Kargopolov",
"email": "test@test.com",
"enabled": "true",
"username": "app-user"
}'
TOKEN=$(curl -k -sS -d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password" \
http://$KEYCLOAK_IP/auth/realms/master/protocol/openid-connect/token)
curl -k -sS -X POST https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "$USER_JSON_DATA"
$USER\u JSON\u DATA
将是要创建的用户的JSON数据表示形式。默认情况下,无需将角色admin添加到使用KeyClope部署的主admin
如果安装正常,您只需要知道(正如我已经描述的)管理员的名称和密码,这是在初始安装中配置的
如果单击管理员用户>角色,您将看到以下内容:
管理员用户已具有管理员角色
编辑:我尝试了密码授予的方式来获得承载令牌和
这是有效的,但不是客户的秘密方式。我显然更喜欢这个
客户秘密通道(这是我目前遇到的问题)。可能是什么
这里的问题是什么
现在,如果您完全按照原来的方式更改admin_cli配置,则需要将admin角色添加到服务帐户admin cli
用户
现在的问题是Service account admin cli
user位于用户部分。但是,您可以执行以下操作:
服务帐户管理cli
李>
管理员
角色李>
由于service account admin cli
用户现在具有admin
角色,因此代表该用户的令牌请求将包含创建用户所需的权限
如果上述操作不起作用,请执行以下操作转到:
- 境界大师李>
- 客户端>管理cli李>
- 去地图绘制者那里李>
- 点击[创建]李>
- 作为映射器类型,选择“硬编码角色”李>
- 点击选择角色并选择“管理员”李>
- 单击[保存]