Keycloak 向客户端添加资源

Keycloak add resource to client

我尝试使用 keycloak 保护 api 和 UMA 尝试向客户端添加资源,就像在网络界面中一样。我的网络界面问题是,我找不到将资源所有者设置为用户的方法。 每当我尝试使用 body

向 http://IP:PORT/auth/realms/REALM_NAME/authz/protection/resource_set 发送请求时
{
     "name":"test",
     "type":"http://www.someurl.com/api",
     "icon_uri":"http://www.someurl.com/etc",
     "resource_scopes":[
         "read"
      ]
}

和一个范围为 openid、uma_authorization、uma_protection 和电子邮件(角色为 uma_authorization 和 uma_protection)的访问令牌,keycloak 服务器响应

{
    "error": "invalid_scope",
    "error_description": "Requires uma_protection scope."
}

我尝试了所有方法,从将范围授予我的测试用户帐户到将其映射到一个角色。有人可能知道如何通过 API 向客户端添加具有所有者的资源吗?

你可以用这个api

https://{HOST}/auth/realms/master/authz/protection/resource_set

Body:
{

 "owner":"ken", // your user (you should have user in db before creating recource)
 "name":"ken_new_tp4:resource",
 "ownerManagedAccess": true,
  "resource_scopes":[
         "edit",
         "create",
         "view"
      ]
}

但是您应该使用具有访问 UMA 权限的授权令牌。

您可以使用管理员令牌创建或创建客户端(机密(来自 UI 面板,并使用 client_id 和密码登录)

我用管理员api

POST  https://{HOST}/auth/realms/master/protocol/openid-connect/token
{
client_id:admin-cli
scope:openid email
username:user
password:password
client_secret:{SECRET_OF_CLIENT_ADMIN_CLI},
grant_type:password
audience:security-admin-console
}

如果它解决了您的问题,请告诉我