将用户添加到 WSO2 租户返回 401 Unathorized

问题描述

我正在尝试将用户添加到租户。为此,我做了以下工作:

  1. 在 WSO2 实例中创建租户
  2. 为租户服务提供商根据客户端密钥和秘密生成访问令牌
  3. 使用生成的令牌执行端点 https://localhost:9443/t/carbon.super/{tenantId}/api/server/v1/scims2/Users,其中tenantId是租户的id。

执行端点后,我收到错误 401 Unauthorized。任何想法我做错了什么?

我不确定它是否相关,但我注意到当我从主 WSO2 实例(不是租户)生成访问令牌时,我得到了这些范围

"scope": "internal_list_tenants internal_user_mgt_create"

但是,当我使用租户客户端密钥和秘密生成类似的令牌时,具有相同的范围,我只看到

 "scope": "internal_user_mgt_create"

我想这很好,因为 createUser 只需要这个范围,但 401 可能是因为无法获得 internal_list_tenants 范围所需的租户?

解决方法

错误的 URL 会导致 401 响应。 此处,您使用的网址 (https://localhost:9443/t/carbon.super/{tenantId}/api/server/v1/scims2/Users) 不正确。

为了在名为 abc.com 的租户中创建用户,您需要调用端点

https://localhost:9443/t/abc.com/scim2/Users

一般来说,如果要在租户中创建用户,端点为:

https://<host>:<port>/t/<tenant-domain>/scim2/Users

如果 URL 中未指定租户,则将其视为超级租户(carbon.super)(https://<host>:<port>/scim2/Users 等于 https://<host>:<port>/t/carbon.super/scim2/Users)。

拥有 "scope": "internal_user_mgt_create" 足以成功执行用户创建 rest API。如果缺少所需的范围/权限,您将收到 403 响应。