/// <summary> /// 批量添加策略 /// </summary> /// <param name="code">角色唯一标志</param> /// <param name="policies">策略 ID 列表</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommonMessage> AddPolicies( string code, IEnumerable <string> policies, CancellationToken cancellationToken = default) { var param = new AddPolicyAssignmentsParam(policies, PolicyAssignmentTargetType.ROLE) { TargetIdentifiers = new string[] { code }, }; var res = await client.Request <AddPolicyAssignmentsResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }
/// <summary> /// 添加策略 /// </summary> /// <param name="userId">用户 ID</param> /// <param name="policies">策略列表</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommonMessage> AddPolicies( string userId, IEnumerable <string> policies, CancellationToken cancellationToken = default) { var param = new AddPolicyAssignmentsParam() { TargetType = PolicyAssignmentTargetType.USER, TargetIdentifiers = new string[] { userId }, Policies = policies, }; await client.GetAccessToken(); var res = await client.Request <AddPolicyAssignmentsResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }
/// <summary> /// 添加策略授权 /// </summary> /// <param name="policies">策略 code 列表</param> /// <param name="targetType"></param> /// <param name="targetIdentifiers">可选值为 USER (用户) 和 ROLE (角色)</param> /// <param name="cancellationToken">用户 id 列表和角色 code 列表</param> /// <returns></returns> public async Task <CommonMessage> AddAssignments( IEnumerable <string> policies, PolicyAssignmentTargetType targetType, IEnumerable <string> targetIdentifiers, CancellationToken cancellationToken = default) { var param = new AddPolicyAssignmentsParam(policies, targetType) { TargetIdentifiers = targetIdentifiers, }; await client.GetAccessToken(); var res = await client.Request <AddPolicyAssignmentsResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }