¶ 授权资源
更新时间: 2024-07-24 09:31:53
将一个/多个资源授权给用户、角色、分组、组织机构等主体,且可以分别指定不同的操作权限。
¶ 请求参数
| 名称 | 类型 | 必填 | 默认值 | 描述 | 示例值 | 
|---|---|---|---|---|---|
| list | AuthorizeResourceItem[] | 是 | - | 授权资源列表。 | |
| namespace | string | 否 | - | 所属权限分组的 code。 | default | 
¶ 示例代码
using Authing.CSharp.SDK.Models;
using Authing.CSharp.SDK.Services;
using Authing.CSharp.SDK.Utils;
using Authing.CSharp.SDK.UtilsImpl;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Example
{
    class Program
    {
      private static ManagementClientOptions options;
      private static string ACCESS_Key_ID = "AUTHING_USERPOOL_ID";
      private static string ACCESS_KEY_SECRET = "AUTHING_USERPOOL_SECRET";
      static void Main(string[] args)
      {
          MainAsync().GetAwaiter().GetResult();
      }
      private static async Task MainAsync()
      {
          options = new ManagementClientOptions()
          {
              AccessKeyId = ACCESS_Key_ID,
              AccessKeySecret = ACCESS_KEY_SECRET,
          };
          ManagementClient managementClient = new ManagementClient(options);
        
          IsSuccessRespDto  result = await managementClient.AuthorizeResources
          (  new AuthorizeResourcesDto{                  Namespace= "default" ,
                List= new List<AuthorizeResourceItem>
                {
                    new AuthorizeResourceItem
                    {
                     TargetType= AuthorizeResourceItem.targetType.USER ,
            TargetIdentifiers= new List<string>{"userId1","userId2",} ,
          Resources= new List<ResourceItemDto>
                {
                    new ResourceItemDto
                    {
                     Code= "ecs" ,
            Actions= new List<string>{"ecs:Stop","ecs:Start",} ,
            ResourceType= ResourceItemDto.resourceType.DATA ,
                }
                  },
                }
                  },
            }
          );
        }
    }
}
¶ 请求响应
类型: IsSuccessRespDto
| 名称 | 类型 | 描述 | 
|---|---|---|
| statusCode | number | 业务状态码,可以通过此状态码判断操作是否成功,200 表示成功。 | 
| message | string | 描述信息 | 
| apiCode | number | 细分错误码,可通过此错误码得到具体的错误类型。 | 
| data | IsSuccessDto | 操作是否成功 | 
示例结果:
{
  "statusCode": 200,
  "message": "操作成功",
  "apiCode": 20001,
  "data": {
    "success": true
  }
}
¶ 数据结构
¶ AuthorizeResourceItem
| 名称 | 类型 | 必填 | 描述 | 
|---|---|---|---|
| targetType | string | 是 | 目标对象类型。 枚举值: USER,ROLE,GROUP,DEPARTMENT | 
| targetIdentifiers | array | 是 | 目标对象唯一标志符。 示例值: ["userId1","userId2"] | 
| resources | array | 是 | 授权的资源列表。嵌套类型:ResourceItemDto。 | 
¶ ResourceItemDto
| 名称 | 类型 | 必填 | 描述 | 
|---|---|---|---|
| code | string | 是 | 资源唯一标志符。 示例值: ecs | 
| actions | array | 是 | 资源定义的操作类型。 示例值: ["ecs:Stop","ecs:Start"] | 
| resourceType | string | 是 | 资源类型,如数据、API、按钮、菜单。 枚举值: DATA,API,MENU,BUTTON | 
¶ IsSuccessDto
| 名称 | 类型 | 必填 | 描述 | 
|---|---|---|---|
| success | boolean | 是 | 操作是否成功。 示例值: true |