Esempio n. 1
0
            public async Task <IEnumerable <ResUdv> > ListUdv(UdfTargetType targetType, string targetId, CancellationToken cancellationToken = default)
            {
                var param = new UdvParam(targetType, targetId);
                var res   = await client.Request <UdvResponse>(param.CreateRequest(), cancellationToken);

                return(AuthingUtils.ConvertUdv(res.Result));
            }
Esempio n. 2
0
            public async Task <List <KeyValuePair <string, object> > > GetUdfValue(string userId, CancellationToken cancellation = default)
            {
                var param = new UdvParam(UdfTargetType.USER, userId);
                var res   = await client.Request <UdvResponse>(param.CreateRequest(), cancellation);

                return(AuthingUtils.ConverUdvToKeyValuePair(res.Result));
            }
            public async Task <KeyValuePair <string, object> > GetSpecificUdfValue(string roleId, string udfKey, CancellationToken cancellationToken = default)
            {
                var param = new UdvParam(UdfTargetType.ROLE, roleId);
                var res   = await client.Request <UdvResponse>(param.CreateRequest(), cancellationToken);

                var udfList      = AuthingUtils.ConverUdvToKeyValuePair(res.Result);
                var keyValuePair = udfList.Where(item => item.Key == udfKey).ToList();

                return(keyValuePair[0]);
            }
            public async Task <Dictionary <string, List <KeyValuePair <string, object> > > > GetUdfValueBatch(IEnumerable <string> roleIds, CancellationToken cancellationToken = default)
            {
                var param = new UdfValueBatchParam(UdfTargetType.ROLE, roleIds);
                var res   = await client.Request <UdfValueBatchResponse>(param.CreateRequest(), cancellationToken);

                var dic = new Dictionary <string, List <KeyValuePair <string, object> > >();

                res.Result.ToList().ForEach(
                    item =>
                    dic.Add(item.TargetId, AuthingUtils.ConverUdvToKeyValuePair(item.Data))
                    );
                return(dic);
            }
Esempio n. 5
0
            public async Task <IEnumerable <ResUdv> > SetUdvBatch(UdfTargetType udfTargetType, string targetId, KeyValueDictionary udvList, CancellationToken cancellationToken = default)
            {
                var _udvList = new List <UserDefinedDataInput>();

                udvList.ToList().ForEach(udv => _udvList.Add(new UserDefinedDataInput(udv.Key)
                {
                    Value = udv.Value
                }));
                var param = new SetUdvBatchParam(udfTargetType, targetId)
                {
                    UdvList = _udvList
                };
                var res = await client.Request <SetUdvBatchResponse>(param.CreateRequest(), cancellationToken);

                return(AuthingUtils.ConvertUdv(res.Result));
            }
Esempio n. 6
0
            public async Task <Dictionary <string, List <KeyValuePair <string, object> > > > GetUdfValueBatch(string[] userIds, CancellationToken cancellation = default)
            {
                if (userIds.Length < 1)
                {
                    throw new Exception("empty user id list");
                }
                var param = new UdfValueBatchParam(UdfTargetType.USER, userIds);
                var res   = await client.Request <UdfValueBatchResponse>(param.CreateRequest(), cancellation);

                var dic = new Dictionary <string, List <KeyValuePair <string, object> > >();

                foreach (var item in res.Result)
                {
                    dic.Add(item.TargetId, AuthingUtils.ConverUdvToKeyValuePair(item.Data));
                }
                return(dic);
            }
            public async Task <ProgrammaticAccessAccount> RefreshProgrammaticAccessAccountSecret(
                string programmaticAccessAccountId,
                string programmaticAccessAccountSecret = null,
                CancellationToken cancellationToken    = default
                )
            {
                if (programmaticAccessAccountSecret == null)
                {
                    programmaticAccessAccountSecret = AuthingUtils.GenerateRandomString(32);
                }
                var res = await client.Host.AppendPathSegment("api/v2/applications/programmatic-access-accounts").WithOAuthBearerToken(client.Token).PatchJsonAsync(
                    new
                {
                    id     = programmaticAccessAccountId,
                    secret = programmaticAccessAccountSecret
                },
                    cancellationToken
                    ).ReceiveJson <ProgrammaticAccessAccount>();

                return(res);
            }
 /// <summary>
 /// 生成 codechallenge
 /// </summary>
 /// <returns>codechallenge</returns>
 public string GenerateCodeChallenge()
 {
     return(AuthingUtils.GenerateRandomString(43));
 }