Пример #1
0
        public BDWMInterest()
        {
            InitializeComponent();

            dt.Columns.Add("id", typeof(Int32));
            dt.Columns.Add("name", typeof(string));
            dgQueryResult.ItemsSource = dt.DefaultView;

            AuthHeader h = new AuthHeader();

            //读取
            if (File.Exists(strFilePath))//读取时先要判读INI文件是否存在
            {
                strSec     = System.IO.Path.GetFileNameWithoutExtension(strFilePath);
                h.username = ContentValue(strSec, "Username");
                h.password = Common.DecryptDES(ContentValue(strSec, "Password"), "WpfQuery");//ContentValue(strSec, "Password");
                h.token    = ContentValue(strSec, "Token");
            }
            else
            {
                MessageBox.Show("account.ini文件不存在");
                return;
            }
            InterestServiceClient client = new InterestServiceClient();

            InterestType[] response;
            ResHeader      resHeader = client.getInterest(h, out response);

            foreach (var ba in response)
            {
                dt.Rows.Add(ba.interestId, ba.interestName);
            }
        }
Пример #2
0
        public CustomerDto[] GetCustomersByQueryWS()
        {
            CustomerWSSoapClient client = new CustomerWSSoapClient();

            AuthHeader soapReqHeader = new AuthHeader {
                UserName = "******", Password = "******"
            };
            CustomerQueryDto soapReqBody = new CustomerQueryDto();


            CustomerQueryItemDto[] query = new CustomerQueryItemDto[] { new CustomerQueryItemDto {
                                                                            QueryOperator = QueryOperator.Equals,
                                                                            QueryProperty = CustomerQueryProperty.IdAccountingClient,
                                                                            Value         = "1223"
                                                                        } };

            soapReqBody.QueryItemList = query;

            GetCustomersResponse response;

            try
            {
                response = client.GetCustomersByQueryWS(soapReqHeader, soapReqBody);
            }
            catch (Exception)
            {
                throw;
            }


            CustomerDto[] customerData = response.CustomerList;

            return(customerData);
        }
        public static void setRegionConfig()
        {
            GroupConfigServiceClient client = new GroupConfigServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            RegionConfigType parameters = new RegionConfigType();

            parameters.groupId    = 2562221L;
            parameters.allRegion  = false;
            parameters.regionList = new RegionItemType[2];
            RegionItemType regionType = new RegionItemType();

            regionType.type          = 1;
            regionType.regionId      = 1000;
            parameters.regionList[0] = regionType;
            regionType               = new RegionItemType();
            regionType.type          = 1;
            regionType.regionId      = 2000;
            parameters.regionList[1] = regionType;

            String result = null;

            ResHeader resHeader = client.setRegionConfig(authHeader, parameters, out result);

            Console.WriteLine("GroupConfigService.setRegionConfig(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #4
0
        private Request BuildHttpRequest()
        {
            var methodName = method_selector.SelectedItem.ToString();
            var method     = MethodResolver.Resolve(methodName);

            var hostNameEndPos = Regex.Match(address_bar.Text, "/").Index;

            _hostName = address_bar.Text.Substring(0, hostNameEndPos);
            _resource = address_bar.Text.Substring(hostNameEndPos, address_bar.Text.Length - hostNameEndPos);

            var httpRequest = new Request(method, _hostName, _resource);

            if (Data != null)
            {
                httpRequest.Body = Data;
                httpRequest.AddHeader("Content-Length", Data.Length.ToString());
            }
            else
            {
                httpRequest.AddHeader("Content-Length", "0");
            }

            if (Credentials != null)
            {
                var authHeader = new AuthHeader(Credentials);
                httpRequest.AddHeader(authHeader);
            }

            if (Headers != null)
            {
                httpRequest.AddMultipleHeaders(Headers);
            }

            return(httpRequest);
        }
Пример #5
0
        public static AuthClaim ValidateAuthClaim(string token)
        {
            string[] jwt = token.Split('.');
            if (jwt.Length != 3)
            {
                return(null);
            }

            string authHeader = jwt[0];
            string authClaim  = jwt[1];
            string secret     = jwt[2];

            // check expiration
            string base64String = Tools.Base64Decode(authHeader);

            if (base64String == null)
            {
                return(null);
            }

            AuthHeader header = JsonConvert.DeserializeObject <AuthHeader>(base64String);

            if (header == null || Tools.ConvertToEpoch(DateTime.UtcNow) > header.expiration)
            {
                return(null);
            }

            // check SHA256 hash
            if (!ValidateSHA256(authHeader + authClaim, secret))
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <AuthClaim>(Tools.Base64Decode(authClaim)));
        }
        public static void setTradeSitePrice()
        {
            GroupConfigServiceClient client = new GroupConfigServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            TradeSitePriceType parameters = new TradeSitePriceType();

            parameters.groupId        = 2562221L;
            parameters.tradePriceList = new TradePriceType[1];
            TradePriceType tradePrice = new TradePriceType();

            tradePrice.tradeId           = 2;
            tradePrice.price             = 2.0f;
            parameters.tradePriceList[0] = tradePrice;

            parameters.sitePriceList = new SitePriceType[1];
            SitePriceType sitePrice = new SitePriceType();

            sitePrice.site              = "7k7k.com";
            sitePrice.price             = 2.0f;
            parameters.sitePriceList[0] = sitePrice;

            String result = null;

            ResHeader resHeader = client.setTradeSitePrice(authHeader, parameters, out result);

            Console.WriteLine("GroupConfigService.setTradeSitePrice(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
        public static void setSiteConfig()
        {
            GroupConfigServiceClient client = new GroupConfigServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            SiteConfigType parameters = new SiteConfigType();

            parameters.groupId         = 2562221L;
            parameters.allSite         = false;
            parameters.siteList        = new String[2];
            parameters.siteList[0]     = "7k7k.com";
            parameters.siteList[1]     = "autohome.com.cn";
            parameters.categoryList    = new int[2];
            parameters.categoryList[0] = 1;
            parameters.categoryList[1] = 2;

            String result = null;

            ResHeader resHeader = client.setSiteConfig(authHeader, parameters, out result);

            Console.WriteLine("GroupConfigService.setSiteConfig(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #8
0
        public static void AddToNewsletter(Newsletter item)
        {
            List <int> ListIDs = new List <int>();

            ListIDs.Add(103435);
            string ClientUser     = "******";
            string ClientPassword = "******";

            try
            {
                CustomerServiceSoapClient client = new CustomerServiceSoapClient();
                AuthHeader authHeader            = new AuthHeader();
                authHeader.Username = ClientUser;
                authHeader.Password = ClientPassword;
                authHeader.Token    = client.Login(authHeader);


                WebCustomer customer = new WebCustomer();
                customer.Email     = item.NewsletterEmail;
                customer.FirstName = item.NewsletterName;
                customer.Phone1    = item.NewsletterPhone;

                APIResponse response = client.ImportCustomer(authHeader, customer, ListIDs.ToArray(), new int[0]);
            }
            catch (Exception ex)
            {
                SF.LogError(ex);
            }
        }
        public string[] GetCurrencyNode()
        {
            AKCurrency.DataServiceSoapClient clien = new DataServiceSoapClient();
            AuthHeader ahd = new AuthHeader();

            ahd.Username = "******";
            ahd.Password = "******";
            var          currency = clien.GetMain(ahd);
            HtmlDocument result   = new HtmlDocument();

            result.LoadHtml(currency);
            HtmlNodeCollection name     = result.DocumentNode.SelectNodes("//kod");
            HtmlNodeCollection purchase = result.DocumentNode.SelectNodes("//alis");
            HtmlNodeCollection sales    = result.DocumentNode.SelectNodes("//satis");
            HtmlNodeCollection date     = result.DocumentNode.SelectNodes("//guncellenmezamani");

            string[] usd = new string[8];
            usd[0] = name[0].InnerText;
            usd[1] = purchase[0].InnerText;
            usd[2] = sales[0].InnerText;
            usd[3] = date[0].InnerText;
            usd[4] = name[1].InnerText;
            usd[5] = purchase[1].InnerText;
            usd[6] = sales[1].InnerText;
            usd[7] = date[1].InnerText;
            return(usd);
        }
Пример #10
0
        public static void updateAd()
        {
            AdServiceClient service = new AdServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            AdType[] parameters = new AdType[1];
            parameters[0]                 = new AdType();
            parameters[0].adId            = 27108657L;
            parameters[0].adIdSpecified   = true;
            parameters[0].description1    = "描述1的文字内容-图文";
            parameters[0].description2    = "描述2的文字内容-图文";
            parameters[0].displayUrl      = "www.baidu.com";
            parameters[0].destinationUrl  = "http://www.baidu.com";
            parameters[0].imageData       = ImageUtils.GetImageDataFromFile("../../data/60_60.jpg");
            parameters[0].width           = 60;
            parameters[0].widthSpecified  = true;
            parameters[0].height          = 60;
            parameters[0].heightSpecified = true;
            parameters[0].title           = "创意标题内容-图文";
            parameters[0].type            = 5;
            parameters[0].typeSpecified   = true;

            ResHeader resHeader = service.updateAd(authHeader, ref parameters);

            Console.WriteLine("AdService.updateAd(): ");
            ObjectDumper.WriteResponse(resHeader, parameters);
        }
Пример #11
0
        public static void addGroup()
        {
            GroupServiceClient client = new GroupServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            GroupType[] groups = new GroupType[1];
            GroupType   group  = new GroupType();

            group.campaignId          = 984757L;
            group.campaignIdSpecified = true;
            group.groupName           = "Demo_" + DateTime.Now.Ticks % 100000;
            group.price          = 1000;
            group.priceSpecified = true;
            group.status         = 0;
            group.type           = 0;
            groups[0]            = group;

            ResHeader resHeader = client.addGroup(authHeader, ref groups);

            Console.WriteLine("GroupService.addGroup(): ");
            ObjectDumper.WriteResponse(resHeader, groups);
        }
        public static void setSiteUrl()
        {
            GroupConfigServiceClient client = new GroupConfigServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            SiteUrlType parameters = new SiteUrlType();

            parameters.groupId     = 2562221L;
            parameters.siteUrlList = new SiteUrlItemType[1];
            SiteUrlItemType siteUrl = new SiteUrlItemType();

            siteUrl.siteUrl           = "autohome.com.cn";
            siteUrl.targetUrl         = "http://baidu.com/autohome.com.cn";
            parameters.siteUrlList[0] = siteUrl;

            String result = null;

            ResHeader resHeader = client.setSiteUrl(authHeader, parameters, out result);

            Console.WriteLine("GroupConfigService.setSiteUrl(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #13
0
 public ExampleAnthillApiMethods()
 {
     // Set the Username and Password values as appropriate
     _authHeader = new AuthHeader {
         Username = "******",
         Password = "******"
     };
 }
Пример #14
0
        public static void execute()
        {
            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);
            AccountServiceClient client  = new AccountServiceClient("AccountService", "https://api.baidu.com/sem/nms/v2/AccountService");
            AccountInfoType      account = getAccountInfo(client, authHeader);
        }
Пример #15
0
 public static string ToAuthorizationHeaderName(this AuthHeader header)
 {
     if (header == AuthHeader.Www)
     {
         return("Authorization");
     }
     return("Proxy-Authorization");
 }
Пример #16
0
 public static string ToAuthenticationHeaderName(this AuthHeader header)
 {
     if (header == AuthHeader.Www)
     {
         return("WWW-Authenticate");
     }
     return("Proxy-Authenticate");
 }
Пример #17
0
        private void btGet_Click(object sender, RoutedEventArgs e)
        {
            //AuthHeader h = new AuthHeader();
            ////读取
            //if (File.Exists(strFilePath))//读取时先要判读INI文件是否存在
            //{
            //    strSec = System.IO.Path.GetFileNameWithoutExtension(strFilePath);
            //    h.username = ContentValue(strSec, "Username");
            //    h.password = Common.DecryptDES(ContentValue(strSec, "Password"), "WpfQuery");//ContentValue(strSec, "Password");
            //    h.token = ContentValue(strSec, "Token");
            //}

            //AccountServiceClient client = new AccountServiceClient();
            //AccountInfoType ait;
            //ResHeader resHeader = client.getAccountInfo(h, out ait);
            //MessageBox.Show(resHeader.desc);


            if (txtKeyword.Text.Trim() == "")
            {
                MessageBox.Show("请输入关键词!");
            }
            else
            {
                dt.Rows.Clear();
                string     key = txtKeyword.Text.Trim();//赋值
                AuthHeader h   = new AuthHeader();
                //读取
                if (File.Exists(strFilePath))//读取时先要判读INI文件是否存在
                {
                    strSec     = System.IO.Path.GetFileNameWithoutExtension(strFilePath);
                    h.username = ContentValue(strSec, "Username");
                    h.password = Common.DecryptDES(ContentValue(strSec, "Password"), "WpfQuery"); //ContentValue(strSec, "Password");
                    h.token    = ContentValue(strSec, "Token");
                }
                else
                {
                    MessageBox.Show("account.ini文件不存在");
                    return;
                }
                KRServiceClient client = new KRServiceClient();

                KRResultType[] response = getKRbySeedWord(client, h, txtKeyword.Text.Trim());



                int num = 1;
                if (response != null)
                {
                    foreach (var ba in response)
                    {
                        dt.Rows.Add(num, ba.word, ba.avgShowCnt.ToString(), ba.cmpDegree.ToString());
                        num++;
                    }
                }
            }
        }
Пример #18
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var headers = new AuthHeader(actionContext.Request.Headers?.ToString());

            if (actionContext.Request.IsLocal() || headers.AuthSignatureBypass)
            {
                return;
            }

            var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
            var roles      = new string[8];

            if ((authCookie == null || authCookie.Value == "") && string.IsNullOrEmpty(headers.Auth))
            {
                actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent($"Please re-authenticate. Missing cookie or '{BlueConstants.AUTH_NAME}' header.")
                };

                base.OnAuthorization(actionContext);
                return;
            }

            try
            {
                var authtoken  = string.IsNullOrWhiteSpace(authCookie?.Value) ? headers.Auth : authCookie.Value;
                var authTicket = FormsAuthentication.Decrypt(authtoken);

                if (authTicket != null)
                {
                    roles = authTicket.UserData.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }

                if (HttpContext.Current.User != null)
                {
                    HttpContext.Current.User = new GenericPrincipal(HttpContext.Current.User.Identity, roles);
                }

                if ((Roles != null) && !Roles.Split(',').Any(roles.Contains))
                {
                    actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized)
                    {
                        Content = new StringContent("Resource inaccessible by group. Please re-authenticate.")
                    };
                }
            }
            catch
            {
                actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent("Please re-authenticate. Invalid AUTH token.")
                };
            }

            base.OnAuthorization(actionContext);
        }
Пример #19
0
        public static string ToAuthorizationHeader(this AuthHeader auth, string clientSecret)
        {
            //var requestString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(header.Split(':')[0]));
            //var requestParts = requestString.Split('|');

            var requestBase64 = auth.Request.ToAuthorizationHeader();
            var dataHash      = auth.ToHMAC(clientSecret);

            return(string.Concat(requestBase64, ":", dataHash));
        }
        //---------------------------------------------------------------------------------------//

        private LabServerWebService GetLabServer(sbAuthHeader sbHeader)
        {
            const string STRLOG_MethodName = "GetLabServer";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            long   couponId      = sbHeader.couponID;
            string couponPasskey = sbHeader.couponPassKey;

            Logfile.Write(" Coupon Id: " + couponId.ToString());
            Logfile.Write(" Coupon Passkey: " + couponPasskey);

            LabServerWebService labServer = null;

            try
            {
                //
                // Get settings from Application's configuration file
                //
                string labserverId = couponId.ToString();

                Logfile.Write(" Labserver Id: " + labserverId);

                string labServerUrl  = Utilities.GetAppSetting(labserverId);
                string sbGuid        = Utilities.GetAppSetting(Consts.STRCFG_ServiceBrokerGuid);
                string sbToLsPasskey = Utilities.GetAppSetting(Consts.STRCFG_SbToLsPasskey);

                Logfile.Write(" ServiceBroker Guid: " + sbGuid);
                Logfile.Write(" Labserver Url: " + labServerUrl);
                Logfile.Write(" SBtoLS Passkey: " + sbToLsPasskey);

                //
                // Create LabServer interface
                //
                labServer     = new LabServerWebService();
                labServer.Url = labServerUrl;

                //
                // Create and fill in authorisation information
                //
                AuthHeader authHeader = new AuthHeader();
                authHeader.identifier     = sbGuid;
                authHeader.passKey        = sbToLsPasskey;
                labServer.AuthHeaderValue = authHeader;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return(labServer);
        }
Пример #21
0
        /// <summary>
        /// Get the necessary paypal API auth header from our setting group.
        /// </summary>
        /// <param name="paypalSettingGroup"></param>
        /// <returns></returns>
        public static AuthHeader GetAuthHeaderFromSetting(SettingGroup paypalSettingGroup)
        {
            AuthHeader PayPalAuthHeader = new AuthHeader();

            PayPalAuthHeader.BaseApiURL = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_API);
            PayPalAuthHeader.Username = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Username);
            PayPalAuthHeader.Password = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Password);
            PayPalAuthHeader.Signature = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Signature);

            return PayPalAuthHeader;
        }
Пример #22
0
        /// <summary>
        /// Get the necessary paypal API auth header from our setting group.
        /// </summary>
        /// <param name="paypalSettingGroup"></param>
        /// <returns></returns>
        public static AuthHeader GetAuthHeaderFromSetting(SettingGroup paypalSettingGroup)
        {
            AuthHeader PayPalAuthHeader = new AuthHeader();

            PayPalAuthHeader.BaseApiURL = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_API);
            PayPalAuthHeader.Username   = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Username);
            PayPalAuthHeader.Password   = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Password);
            PayPalAuthHeader.Signature  = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Signature);

            return(PayPalAuthHeader);
        }
Пример #23
0
        public static AccountInfoType getAccountInfo(AccountServiceClient client, AuthHeader authHeader)
        {
            AccountInfoType response = null;

            ResHeader resHeader = client.getAccountInfo(authHeader, out response);

            Console.WriteLine("AccountService.getAccountInfo(): ");
            ObjectDumper.WriteResponse(resHeader, response);

            return(response);
        }
 /// <summary>
 /// Remove the authorization HTTP header if it's not equal to the old one.
 /// </summary>
 /// <param name="parameters">List of HTTP headers</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 /// <returns>true = header removed, false = same header already exists, null = header not found</returns>
 public static bool? RemoveAuthorizationHeader(IList<Parameter> parameters, AuthHeader header, string authValue)
 {
     var authParam = parameters.SingleOrDefault(
         p => p.Name.Equals(header.ToAuthorizationHeaderName(), StringComparison.OrdinalIgnoreCase));
     if (authParam == null)
         return null;
     var v = (string)authParam.Value;
     if (v != null && v == authValue)
         return false;
     parameters.Remove(authParam);
     return true;
 }
Пример #25
0
        public static KRResultType[] getKRbySeedWord(KRServiceClient client, AuthHeader h, string keyword)
        {
            KRResultType[] response;
            int[]          packids    = new int[] { };
            int[]          regionlist = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 99, 101, 102, 103, 104, 105, 106, 107, 110, 111, 112, 113, 115, 116, 118, 119, 120, 121, 124, 126, 127, 128, 129, 130, 131, 132, 138, 139, 140, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 156, 157, 158, 160, 162, 163, 164, 166, 167, 169, 170, 172, 173, 174, 175, 176, 180, 182, 184, 185, 186, 187, 188, 189, 191, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 208, 210, 211, 212, 213, 215, 217, 218, 219, 220, 221, 223, 225, 226, 228, 229, 230, 231, 234, 236, 239, 240, 241, 242, 243, 246, 249, 250, 252, 253, 254, 255, 256, 257, 258, 261, 262, 263, 266, 267, 268, 272, 273, 276, 278, 279, 282, 284, 287, 289, 290, 291, 293, 298, 304, 305, 307, 308, 309, 310, 311, 312, 313, 314, 315, 317, 319, 320, 321, 323, 324, 328, 329, 330, 331, 334, 335, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 351, 352, 355, 356, 358, 359, 361, 363, 367, 375, 376, 377, 381, 383, 386, 391, 392, 393, 395, 399, 401, 402, 403, 404, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 434, 435, 437, 438, 439, 442, 444, 446, 447, 448, 449, 450, 454, 456, 458, 459, 461, 462, 463, 466, 467, 468, 470, 472, 473, 474, 476, 477, 479, 480, 481, 482, 485, 486, 491, 492, 493, 494, 495, 496, 497, 498, 501, 502, 503, 504, 506, 508, 509, 510, 511, 512, 513, 515, 516, 517, 518, 519, 520, 523, 524, 526, 528, 529, 530, 531, 532, 534, 535, 536, 538, 540, 541, 542, 543, 546, 547, 548, 549, 551, 554, 556, 557, 560, 563, 564, 565, 566, 570, 571, 572, 573, 576, 578, 579, 580, 581, 585, 587, 589, 590, 593, 594, 595, 597, 598, 604, 605, 606, 608, 611, 615, 617, 619, 621, 624, 630, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 763, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 830, 831, 832, 833, 834, 835, 836, 837, 867, 868, 869, 870, 900, 901 };
            long           groupId    = 9279682;

            ResHeader resHeader = client.getKRBySeed(h, keyword, groupId, regionlist, 7, 30, packids, "reserved", out response);

            MessageBox.Show(resHeader.desc);
            return(response);
        }
Пример #26
0
        public async Task ShouldReceive200AndValueOnIncrementRequestCount()
        {
            var client = new HttpClient();

            var url    = string.Concat(_address, "/api/values/5");
            var result = await client.GetAsync(url);

            var wwwAuthenticate = result.Headers.WwwAuthenticate.First();

            Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
            StringAssert.Equals(wwwAuthenticate.Scheme, "AuthAPI");

            var responsePayload = new ResponsePayload(wwwAuthenticate.Parameter);

            var requestPayload = new RequestPayload
            {
                ClientId     = "TestAPI",
                Identifier   = responsePayload.Identifier,
                RequestCount = string.Format("{0:D8}", int.Parse(responsePayload.RequestCount) + 1),
                UserName     = "******"
            };

            var dataPayload = new DataPayload
            {
                ClientId          = "TestAPI",
                Method            = "GET",
                Password          = "******",
                RequestBodyBase64 = string.Empty,
                RequestURI        = "/api/values/5",
                UserName          = "******"
            };

            var authHeader = new AuthHeader
            {
                Data    = dataPayload,
                Request = requestPayload
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("AuthAPI", authHeader.ToAuthorizationHeader("QiU6bSt3anE2OURfX3IsKlVZen05K1tBLW5AQ1x1d0xIXVZwaGE7Zj83QTc0ZXthVy9aWV9UZ0tUcnRUVEQ6d2JxTEhGOi9fMitBfiNZOS5NXHlyJzNnNSl1VzxNQExkQXtHJEQ+fWElMkMhWUJhLT8kbUFeQERWa310J2N+NkQ="));

            result = await client.GetAsync(url);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual(await result.Content.ReadAsAsync <string>(), "value");

            authHeader.Request.RequestCount = string.Format("{0:D8}", int.Parse(authHeader.Request.RequestCount) + 1);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("AuthAPI", authHeader.ToAuthorizationHeader("QiU6bSt3anE2OURfX3IsKlVZen05K1tBLW5AQ1x1d0xIXVZwaGE7Zj83QTc0ZXthVy9aWV9UZ0tUcnRUVEQ6d2JxTEhGOi9fMitBfiNZOS5NXHlyJzNnNSl1VzxNQExkQXtHJEQ+fWElMkMhWUJhLT8kbUFeQERWa310J2N+NkQ="));
            result = await client.GetAsync(url);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #27
0
        public async Task ShouldReceive200OnPost()
        {
            var client = new HttpClient();

            var valuesModel = new ValuesModel
            {
                Id   = 1,
                Name = "oi"
            };
            var url    = string.Concat(_address, "/api/values");
            var result = await client.PostAsJsonAsync <ValuesModel>(url, valuesModel);

            var wwwAuthenticate = result.Headers.WwwAuthenticate.First();

            Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
            StringAssert.Equals(wwwAuthenticate.Scheme, "AuthAPI");

            var responsePayload = new ResponsePayload(wwwAuthenticate.Parameter);

            var requestPayload = new RequestPayload
            {
                ClientId     = "TestAPI",
                Identifier   = responsePayload.Identifier,
                RequestCount = string.Format("{0:D8}", int.Parse(responsePayload.RequestCount) + 1),
                UserName     = "******"
            };

            var json = JsonConvert.SerializeObject(valuesModel);

            var dataPayload = new DataPayload
            {
                ClientId          = "TestAPI",
                Method            = "POST",
                Password          = "******",
                RequestBodyBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(valuesModel))),
                RequestURI        = "/api/values",
                UserName          = "******"
            };

            var authHeader = new AuthHeader
            {
                Data    = dataPayload,
                Request = requestPayload
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("AuthAPI", authHeader.ToAuthorizationHeader("QiU6bSt3anE2OURfX3IsKlVZen05K1tBLW5AQ1x1d0xIXVZwaGE7Zj83QTc0ZXthVy9aWV9UZ0tUcnRUVEQ6d2JxTEhGOi9fMitBfiNZOS5NXHlyJzNnNSl1VzxNQExkQXtHJEQ+fWElMkMhWUJhLT8kbUFeQERWa310J2N+NkQ="));

            result = result = await client.PostAsJsonAsync <ValuesModel>(url, valuesModel);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #28
0
        public static void getAllCategory()
        {
            CodeServiceClient client = new CodeServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            CategoryType[] result    = null;
            ResHeader      resHeader = client.getAllCategory(authHeader, out result);

            Console.WriteLine("CodeService.getAllCategory(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #29
0
        public static void getGroupByCampaignId()
        {
            GroupServiceClient client = new GroupServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            GroupType[] result    = null;
            ResHeader   resHeader = client.getGroupByCampaignId(authHeader, 984757L, out result);

            Console.WriteLine("GroupService.getGroupByCampaignId(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #30
0
        public static void getCampaignId()
        {
            CampaignServiceClient client = new CampaignServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            long[]    result    = null;
            ResHeader resHeader = client.getCampaignId(authHeader, out result);

            Console.WriteLine("CampaignService.getCampaignId(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #31
0
        public static AgileLDAPService ASRV()
        {
            AgileLDAPService asrv = new AgileLDAPService();
            AuthHeader       auth = new AuthHeader();

            auth.Username = WebConfigurationManager.AppSettings["auth.Username"];
            if (auth.Username == "SOME_NAME_GOES_HERE" || auth.Username.Trim() == "")
            {
                throw new AccessViolationException();
            }

            auth.Password        = WebConfigurationManager.AppSettings["auth.Password"];
            asrv.AuthHeaderValue = auth;
            return(asrv);
        }
Пример #32
0
        public static void getAllPeople()
        {
            PeopleServiceClient service = new PeopleServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            PeopleType[] peoples = null;

            ResHeader resHeader = service.getAllPeople(authHeader, out peoples);

            Console.WriteLine("PeopleService.getAllPeople(): ");
            ObjectDumper.WriteResponse(resHeader, peoples);
        }
 /// <summary>
 /// Get all authentication header information
 /// </summary>
 /// <param name="response">The response to get the authentication header from</param>
 /// <param name="header">The header to query (WWW or proxy)</param>
 /// <returns>All authentication header information items</returns>
 public static IEnumerable<AuthHeaderInfo> GetAuthenticationHeaderInfo(this IHttpResponseMessage response, AuthHeader header)
 {
     var headerName = header.ToAuthenticationHeaderName();
     IEnumerable<string> headerValues;
     if (!response.Headers.TryGetValues(headerName, out headerValues))
         headerValues = _emptyHeaderValues;
     return headerValues
         .Select(x => new AuthHeaderInfo(x))
         .ToList();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBasicAuthenticator" /> class.
 /// </summary>
 /// <param name="credentials">The credentials to use for preauthentication</param>
 /// <param name="authHeader">Authentication/Authorization header type</param>
 public HttpBasicAuthenticator(NetworkCredential credentials, AuthHeader authHeader)
     : this(credentials.UserName, credentials.Password, authHeader)
 {
     _authCredential = credentials;
 }
        public static IEnumerable<AuthHeaderInfo> GetAuthenticationHeaderInfo([NotNull] this IHttpResponseMessage response, AuthHeader header)
        {
            var headerName = header.ToAuthenticationHeaderName();
            IEnumerable<string> headerValues;
            if (!response.Headers.TryGetValues(headerName, out headerValues))
            {
                headerValues = _emptyHeaderValues;
            }

            return headerValues
                .SelectMany(ParseAuthenticationHeader)
                .ToList();
        }
 /// <summary>
 /// Remove the authorization header from both the client and the request
 /// </summary>
 /// <param name="client">The client to be searched for the HTTP authorization header</param>
 /// <param name="request">The request to be searched for the HTTP authorization header</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 /// <returns>true when the authorization header can be added again</returns>
 public static bool RemoveAuthorizationHeader(IRestClient client, IRestRequest request, AuthHeader header, string authValue)
 {
     var result = RemoveAuthorizationHeader(client.DefaultParameters, header, authValue);
     if (result.HasValue && !result.Value)
         return false;
     return RemoveAuthorizationHeader(request.Parameters, header, authValue).GetValueOrDefault(true);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticationChallengeHandler" /> class.
 /// </summary>
 /// <param name="authHeader">The HTTP header to look for the challenge.</param>
 public AuthenticationChallengeHandler(AuthHeader authHeader)
 {
     Header = authHeader;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBasicAuthenticator" /> class.
 /// </summary>
 /// <param name="userName">The user name to be used for authentication</param>
 /// <param name="password">The password to be used for authentication</param>
 /// <param name="authHeader">Authentication/Authorization header type</param>
 public HttpBasicAuthenticator(string userName, string password, AuthHeader authHeader)
 {
     _authToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{userName}:{password}"));
     _authHeader = authHeader;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBasicAuthenticator" /> class.
 /// </summary>
 /// <param name="authHeader">Authentication/Authorization header type</param>
 public HttpBasicAuthenticator(AuthHeader authHeader)
 {
     _authHeader = authHeader;
 }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 public static void SetAuthorizationHeader(IRestRequest request, AuthHeader header, string authValue)
 {
     request.AddParameter(header.ToAuthorizationHeaderName(), authValue, ParameterType.HttpHeader);
 }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authentication header value</param>
 public static void SetAuthorizationHeader(this IHttpRequestMessage request, AuthHeader header, string authValue)
 {
     var headerName = header.ToAuthorizationHeaderName();
     request.Headers.Remove(headerName);
     request.Headers.Add(headerName, authValue);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpDigestAuthenticator" /> class.
 /// </summary>
 /// <param name="authHeader">Authentication/Authorization header type</param>
 public HttpDigestAuthenticator(AuthHeader authHeader)
 {
     _authHeader = authHeader;
 }
 public static string GetAuthenticationMethodValue([NotNull] this IRestResponse response, AuthHeader header, [NotNull] string methodName)
 {
     return GetAuthenticationHeaderInfo(response, header)
         .Where(x => string.Equals(x.Name, methodName, StringComparison.OrdinalIgnoreCase))
         .Select(x => x.RawValue)
         .SingleOrDefault();
 }
 /// <summary>
 /// Try to set the authorization header
 /// </summary>
 /// <param name="client">The client to remove the old authorization header from</param>
 /// <param name="request">The request to remove the old authorization header from and to add the new header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 /// <returns>true when the authorization header could be set</returns>
 public static bool TrySetAuthorizationHeader(IRestClient client, IRestRequest request, AuthHeader header, string authValue)
 {
     if (!RemoveAuthorizationHeader(client, request, header, authValue))
         return false;
     SetAuthorizationHeader(request, header, authValue);
     return true;
 }
 /// <summary>
 /// Try to get the authentication header value for a given authentication method
 /// </summary>
 /// <param name="response">The response to get the authentication header from</param>
 /// <param name="header">The header to query (WWW or proxy)</param>
 /// <param name="methodName">The method name to query the value for</param>
 /// <returns>The information attached to the authentication header for a given method</returns>
 public static string GetAuthenticationMethodValue(this IHttpResponseMessage response, AuthHeader header, string methodName)
 {
     return GetAuthenticationHeaderInfo(response, header)
         .Where(x => string.Equals(x.Name, methodName, StringComparison.OrdinalIgnoreCase))
         .Select(x => x.Info)
         .SingleOrDefault();
 }
 /// <summary>
 /// Get all authentication header information
 /// </summary>
 /// <param name="response">The response to get the authentication header from</param>
 /// <param name="header">The header to query (WWW or proxy)</param>
 /// <returns>All authentication header information items</returns>
 public static IEnumerable<AuthHeaderInfo> GetAuthenticationHeaderInfo(this IRestResponse response, AuthHeader header)
 {
     var headerName = header.ToAuthenticationHeaderName();
     return response
         .Headers.GetValues(headerName)
         .Select(x => new AuthHeaderInfo(x))
         .ToList();
 }
 public static IEnumerable<AuthHeaderInfo> GetAuthenticationHeaderInfo([NotNull] this IRestResponse response, AuthHeader header)
 {
     var headerName = header.ToAuthenticationHeaderName();
     return response
         .Headers.GetValues(headerName)
         .SelectMany(ParseAuthenticationHeader)
         .ToList();
 }