GenAuth DocsDocuments
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Old version
  • Single Page Web Application

  • Mobile and Client Applications

    • Android

    • C#

      • User Authentication Module

      • Management Module

        • 管理用户
        • 管理应用
        • 管理角色
        • 管理资源与权限
        • 管理分组
        • 管理组织机构
        • 管理用户自定义字段
        • 管理注册白名单
        • 管理用户池配置
        • 管理日志统计信息
        • 管理多租户
    • Flutter

    • iOS

    • React Native
  • Standard Web Application

  • Framework Integration

  • Others

  1. Development Integration
  2. /
  3. Mobile and Client Applications
  4. /
  5. C#
  6. /
  7. Management Module
  8. /
  9. 管理角色

¶ 管理角色

Update time: 2025-07-23 07:34:21
Edit

此模块用于管理 GenAuth 角色,可以进行角色的增删改查、角色添加/删除用户、角色添加/删除策略 等操作。

¶ 创建角色

managementClient.Roles.Create(string code, string description = null,string parentCode = null ,string nameSpace=null)

创建角色

¶ 参数

  • code <string> 角色唯一标志符
  • description <string> 角色描述
  • parentCode <string> 父角色唯一标志符

¶ 示例

managementClient.Roles.Create("code");

¶ 删除角色

managementClient.Roles.Delete(string code)

删除角色

¶ 参数

  • code <string> 角色唯一标志符

¶ 示例

managementClient.Roles.Delete("code");

¶ 批量删除角色

managementClient.Roles.DeleteMany(IEnumerable<string> codeList)
managementClient.Roles.DeleteMany(IEnumerable<string> codeList,string nameSpace = null)

批量删除角色

¶ 参数

  • codeList <IEnumerable<string> 角色唯一标志符列表

¶ 示例

var list = new List<string>(){};
managementClient.Roles.DeleteMany(list);

¶ 修改角色

managementClient.Roles.Update(string code, string description = null,string newCode = null)
managementClient.Roles.Update(UpdateRoleOptions updateRoleOptions)

修改角色

¶ 参数

  • code <string> 角色唯一标志符
  • description <string> 描述信息
  • newCode <string> 新的唯一标志符
  • input <UpdateRoleParam>
  • input.code <string> 角色唯一标志符
  • input.description <string> 描述信息
  • input.newCode <string> 新的唯一标志符
  • input.namespace <string> 权限分组的 Code,详情请见使用权限分组管理权限资源。

¶ 示例

managementClient.Roles.Update("oldCode","description","newCode);

¶ 查询角色详情

managementClient.Roles.FindByCode(string code,string nameSpace = null)

获取角色详情

¶ 参数

  • code <string> 角色唯一标识
  • namespace <string> 权限分组的 Code,详情请见使用权限分组管理权限资源。

¶ 示例

var result = await managementClient.Roles.FindByCode("code","nameSpace");

¶ 获取角色详情

managementClient.Roles.Detail(string code,string nameSpace = null)

获取角色详情

¶ 参数

  • code <string> 角色唯一标识
  • namespace <string> 权限分组的 Code,详情请见使用权限分组管理权限资源。

¶ 示例

var result = await managementClient.Roles.Detail("code","nameSpace");

¶ 获取角色列表

managementClient.Roles.List(int page = 1,int limit = 10)

获取角色列表

¶ 参数

  • page <int> 页码数,默认值:1。
  • limit <int> 每页个数,默认值:10。

¶ 示例

var result = await managementClient.Roles.List(int page = 1,int limit = 10);

¶ 获取用户列表

managementClient.Roles.ListUsers(string code)

获取用户列表

¶ 参数

  • code <string> 角色唯一标志符

¶ 示例

var users = await managementClient.Roles.ListUsers("code");

¶ 添加用户

managementClient.Roles.AddUsers(string code,IEnumerable<string> userIds, nameSpace = null)

添加用户

¶ 参数

  • code <string> 角色唯一标志符
  • userIds <List<string>> 用户 ID 列表
  • nameSpace <string> 分组ID

¶ 示例

var userIds = new List<string>(){ "userId" };
managementClient.Roles.AddUsers("code", userIds,"nameSpace");

¶ 移除用户

 managementClient.Roles.RemoveUsers(string code,IEnumerable<string> userIds,string nameSpace = null)

移除用户

¶ 参数

  • code <string> 角色唯一标志符
  • userIds <List<string>> 用户 ID 列表
  • namespace <string> 权限分组的 Code

¶ 示例

var userIds = new List<string>(){ "userId" };
managementClient.Roles.RemoveUsers("code", userIds);

¶ 获取策略列表

managementClient.Roles.ListPolicies(string code,int page = 1,int limit = 10)

获取策略列表

¶ 参数

  • code <string> 角色唯一标志符
  • page <int> 页码数,默认值:1。
  • limit <int> 每页个数,默认值:10。

¶ 示例

managementClient.Roles.ListPolicies("code", 1, 10);

¶ 批量添加策略

managementClient.Roles.AddPolicies(string code,IEnumerable<string> policies)

批量添加策略

¶ 参数

  • code <string> 角色唯一标志符
  • policies <List<string>> 策略唯一标识的集合

¶ 示例

var list = new List<string>(){ "id" };
managementClient.Roles.AddPolicies("code",list );

¶ 批量移除策略

managementClient.Roles.RemovePolicies(string code,IEnumerable<string> policies)

批量移除策略

¶ 参数

  • code <string> 角色唯一标志符
  • policies <List<string>> 策略唯一标识的集合

¶ 示例

var list = new List<string>(){ "id };
managementClient.Roles.RemovePolicies("code", list);

¶ 获取角色被授权的所有资源列表

managementClient.Roles.ListAuthorizedResources(string code, string nameSpace, ResourceType resourceType = default)

获取一个角色被授权的所有资源。

¶ 参数

  • code <string> 角色 Code
  • namespace <string> 权限分组的 Code,详情请见使用权限分组管理权限资源。
  • resourceType <ResourceType> 可选,资源类型,默认会返回所有有权限的资源,现有资源类型如下:
    • DATA:数据类型;
    • API:API 类型数据;
    • MENU:菜单类型数据;
    • BUTTON:按钮类型数据。

¶ 示例

var result = await managementClient.Roles.ListAuthorizedResources("code", "roleGroupCode");

¶ 示例数据

  • type 资源类型
  • code 资源描述符,如果是 DATA 类型资源,格式为 resourceType:resourceId,如 books:* 表示所有书籍,books:1 表示 ID 为 1 的书籍。
  • actions 用户被授权对该资源的操作
{
  "totalCount": 12,
  "list": [
    {
      "code": "menu_a",
      "type": "MENU"
    },
    {
      "code": "menu_b",
      "type": "MENU"
    },
    {
      "code": "books:1",
      "type": "DATA",
      "actions": ["books:delete", "books:update"]
    }
  ]
}

¶ 获取某个角色扩展字段列表

managementClient.Roles.GetUdfValue(string roleCode)

获取某个角色扩展字段列表

¶ 参数

  • roleCode <string> 角色 Code

¶ 示例

managementClient.Roles.GetUdfValue("ROLE_CODE");

¶ 获取某个角色某个扩展字段

managementClient.Roles.GetSpecificUdfValue(string roleId, string udfKey)

获取某个角色某个扩展字段

¶ 参数

  • roleCode <string> 角色 Code
  • udfKey <string> 角色自定义扩展字段的 Key

¶ 示例

managementClient.Roles.GetSpecificUdfValue("ROLE_CODE");

¶ 获取多个角色扩展字段列表

managementClient.Roles.GetUdfValueBatch(IEnumerable<string> roleIds)

获取多个角色扩展字段列表

¶ 参数

  • roleCodes <List<string>> 角色 Code 列表

¶ 示例

var codeList = new List<string>(){ "roleId" };
var udfMap = await managementClient.Roles.GetUdfValueBatch(codeList);

¶ 设置角色扩展字段列表

managementClient.Roles.SetUdfValue(SetUdfValueParam setUdfValueParam)

设置角色扩展字段列表

¶ 参数

  • SetUdfValueParam.RoleId <string> 角色 ID
  • SetUdfValueParam.UdvList <Map<string, string>> 字段映射 Map
  • UdvList.key <string> 字段 Key
  • UdvList.value <string> 字段 Value

¶ 示例

var list = await managementClient.Roles.SetUdfValue("RoleId");

¶ 设置多个角色扩展字段列表

managementClient.Roles.SetUdfValueBatch(IEnumerable<SetUdfValueParam> setUdfValueBatchParam)

设置多个角色扩展字段列表

¶ 参数

  • setUdfValueBatchParam <List<SetUdfValueParam>>
  • <SetUdfValueParam>
    • roleCode <string> 角色 Code
    • data <Map<string, string>> 字段 Map

¶ 示例

var list = await managementClient.Roles.SetUdfValue("RoleId");

¶ 移除用户自定义数据

managementClient.Roles.RemoveUdfValue(string roleId, string key)

移除用户自定义数据

¶ 参数

  • code <string> 角色 Code
  • key <string> 字段 Key

¶ 示例

managementClient.Roles.RemoveUdfValue("code", "key")
Previous article: 管理应用 Next article: 管理资源与权限
  • 创建角色
  • 删除角色
  • 批量删除角色
  • 修改角色
  • 查询角色详情
  • 获取角色详情
  • 获取角色列表
  • 获取用户列表
  • 添加用户
  • 移除用户
  • 获取策略列表
  • 批量添加策略
  • 批量移除策略
  • 获取角色被授权的所有资源列表
  • 获取某个角色扩展字段列表
  • 获取某个角色某个扩展字段
  • 获取多个角色扩展字段列表
  • 设置角色扩展字段列表
  • 设置多个角色扩展字段列表
  • 移除用户自定义数据

User identity management

Integrated third-party login
Customized authentication process

Enterprise internal management

Single sign-on
Multi-factor authentication
Permission management

Developer

Development Documentation
GitHub (opens new window)

Company

official@genauth.ai
16th Floor, Building B, Beichen Century Center, Chaoyang District, Beijing (Total)
Room 406, 4th Floor, Block B, No. 200, Tianfu Fifth Street, High-tech Zone, Chengdu (Branch)

© Beijing Steamory Technology Co., Ltd.