【发布时间】:2019-05-22 10:22:03
【问题描述】:
我正在尝试使用 keycloak AdminAPI (https://www.keycloak.org/docs-api/3.0/rest-api/index.html#_users_resource) 创建用户并分配客户端角色。我收到了正确的令牌,并且创建了用户但分配角色返回 404
我正在使用 Postman 连接 API:
/auth/realms/{realmName}/protocol/openid-connect/token
Content-Type application/x-www-form-urlencoded <-with parameters ofc
/auth/admin/realms/{realmName}/users
Content-Type application/json
Authorization Bearer {TOKEN}
Body:
{
"username": "name",
"enabled": true,
"emailVerified": false,
"firstName": "first",
"lastName": "last",
"credentials": [
{
"type": "password",
"value": "newPas1*",
"temporary": false
}
]
}
上面的对我有用,但下一个不适合
/auth/admin/realms/{realmName}/users/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/role-mappings/clients/realm-management
Content-Type application/json
Authorization Bearer {TOKEN}
Body:
{
"roles": [
{
"id": "0830ff39-43ea-48bb-af8f-696bc420c1ce",
"name": "create-client",
"description": "${role_create-client}",
"composite": false,
"clientRole": true,
"containerId": "344e7c81-e7a2-4a43-b013-57d7ed198eee"
}
]
}
其中 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx' 是创建期间返回的用户 ID,并且存在 create-client 角色
我需要一种通过 Http 请求添加客户端角色的方法。我看到有一些针对 java 的 keycloack 实现,但我使用的是 .NET CORE,所以会有目标实现,但我需要先有工作请求,正如你可能猜到的那样
【问题讨论】:
标签: api http-status-code-404 admin keycloak