Exemple #1
0
            /// <summary>
            /// 获取白名单
            /// </summary>
            /// <param name="type">白名单类型,USERNAME 为用户名、Email 为邮箱、Phone 为手机号。</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <IEnumerable <WhiteList> > List(WhitelistType type, CancellationToken cancellationToken = default)
            {
                var param = new WhitelistParam(type);

                await client.GetAccessToken();

                var res = await client.Request <WhitelistResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
Exemple #2
0
            /// <summary>
            /// 用户池详情
            /// </summary>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <UserPool> Detail(CancellationToken cancellationToken = default)
            {
                var param = new UserpoolParam();

                await client.GetAccessToken();

                var res = await client.Request <UserpoolResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
Exemple #3
0
            /// <summary>
            /// 设置自定义字段元数据,如果字段不存在则会创建,存在会更新
            /// </summary>
            /// <param name="type">自定义字段目标类型, USER 表示用户、ROLE 表示角色。</param>
            /// <param name="key">字段 key</param>
            /// <param name="dataType">数据类型,目前共支持五种数据类型。STRING 为字符串、NUMBER 为数字、DATETIME 为日期、BOOLEAN 为 boolean 值、OBJECT 为对象。</param>
            /// <param name="label">字段 Label,一般是一个 Human Readable 字符串。</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <UserDefinedField> Set(
                UdfTargetType type,
                string key,
                UdfDataType dataType,
                string label,
                CancellationToken cancellationToken = default)
            {
                var param = new SetUdfParam(type, key, dataType, label);

                await client.GetAccessToken();

                var res = await client.Request <SetUdfResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
            /// <summary>
            /// 允许某个用户操作某个资源
            /// </summary>
            /// <param name="resource"></param>
            /// <param name="action"></param>
            /// <param name="userId"></param>
            /// <param name="role"></param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            /// TODO: 下个大版本去除
            /// WARNING: 去除 CancellationToken cancellationToken = default 参数以避免与重载函数冲突
            public async Task <CommonMessage> Allow(
                string resource,
                string action,
                string userId = null,
                string role   = null
                )
            {
                var param = new AllowParam(resource, action)
                {
                    UserId   = userId,
                    RoleCode = role,
                };
                await client.GetAccessToken();

                var res = await client.Request <AllowResponse>(param.CreateRequest());

                return(res.Result);
            }
            /// <summary>
            /// 删除角色
            /// </summary>
            /// <param name="code">角色唯一标志</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            /// TODO: 在下一个大版本中去除
            public async Task <CommonMessage> Delete(
                string code,
                CancellationToken cancellationToken = default)
            {
                var param = new DeleteRoleParam(code);
                await client.GetAccessToken();

                var res = await client.Request <DeleteRoleResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
Exemple #6
0
            /// <summary>
            /// 获取分组列表
            /// </summary>
            /// <param name="page">分页页数,默认为 1</param>
            /// <param name="limit">分页大小,默认为 10</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <PaginatedGroups> List(
                int page  = 1,
                int limit = 10,
                CancellationToken cancellationToken = default)
            {
                var param = new GroupsParam()
                {
                    Page  = page,
                    Limit = limit,
                };

                await client.GetAccessToken();

                var res = await client.Request <GroupsResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
            /// <summary>
            /// 获取策略列表
            /// </summary>
            /// <param name="page">分页页数,默认为 1</param>
            /// <param name="limit">分页大小,默认为 10</param>
            /// <param name="excludeDefault">包含系统默认的策略,默认为 true</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <PaginatedPolicies> List(
                int page            = 1,
                int limit           = 10,
                bool excludeDefault = true,
                CancellationToken cancellationToken = default)
            {
                var param = new PoliciesParam()
                {
                    Page  = page,
                    Limit = limit,
                    // ExcludeDefault = excludeDefault,
                };

                await client.GetAccessToken();

                var res = await client.Request <PoliciesResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
        public static async Task <ManagementClient> InitManagementClient(string userPoolId, string secret)
        {
            var manageClient = new ManagementClient(userPoolId, secret);
            await manageClient.GetAccessToken();

            manageClient.Users     = new UsersManagementClient(manageClient);
            manageClient.Roles     = new RolesManagementClient(manageClient);
            manageClient.Acl       = new AclManagementClient(manageClient);
            manageClient.Groups    = new GroupsManagementClient(manageClient);
            manageClient.Udf       = new UdfManagementClient(manageClient);
            manageClient.Whitelist = new WhitelistManagementClient(manageClient);
            manageClient.Userpool  = new UserpoolManagementClient(manageClient);
            manageClient.Policies  = new PoliciesManagementClient(manageClient);
            return(manageClient);
        }
        public static async Task <ManagementClient> InitManagementClient(Action <InitAuthenticationClientOptions> init)
        {
            var manageClient = new ManagementClient(init);
            await manageClient.GetAccessToken();

            manageClient.Users     = new UsersManagementClient(manageClient);
            manageClient.Roles     = new RolesManagementClient(manageClient);
            manageClient.Acl       = new AclManagementClient(manageClient);
            manageClient.Groups    = new GroupsManagementClient(manageClient);
            manageClient.Orgs      = new OrgManagementClient(manageClient);
            manageClient.Udf       = new UdfManagementClient(manageClient);
            manageClient.Whitelist = new WhitelistManagementClient(manageClient);
            manageClient.Userpool  = new UserpoolManagementClient(manageClient);
            manageClient.Policies  = new PoliciesManagementClient(manageClient);
            return(manageClient);
        }
Exemple #10
0
            /// <summary>
            /// 获取用户信息
            /// </summary>
            /// <param name="userId">用户 ID</param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            /// TODO: 下个大版本去除
            public async Task <User> Detail(
                string userId,
                CancellationToken cancellationToken = default)
            {
                var param = new UserParam()
                {
                    Id = userId
                };
                await client.GetAccessToken();

                var res = await client.Request <UserResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }