Beispiel #1
0
        public static bool TryParse(string input, out ApiRequestSignature parsedValue)
        {
            parsedValue = null;
            var success = false;

            if (input != null)
            {
                var parts = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 3)
                {
                    if (parts[2].Length == 64)
                    {
                        DateTime timestamp;
                        if (DateTime.TryParseExact(
                                parts[1],
                                "o",
                                CultureInfo.InvariantCulture,
                                DateTimeStyles.AdjustToUniversal,
                                out timestamp))
                        {
                            parsedValue = new ApiRequestSignature
                            {
                                AppId           = parts[0],
                                TimestampString = parts[1],
                                Hash            = parts[2],
                                Timestamp       = timestamp,
                            };
                            success = true;
                        }
                    }
                }
            }

            return(success);
        }
        protected override RestRequest PrepareRequest(string path, Method method, Dictionary<string, string> queryParams, string postBody, Dictionary<string, string> headerParams,
            Dictionary<string, string> formParams, Dictionary<string, FileParameter> fileParams, Dictionary<string, string> pathParams)
        {
            var request = base.PrepareRequest(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);

            var signature = new ApiRequestSignature { AppId = _appId };

            var parameters = new[]
            {
                new NameValuePair(null, _appId),
                new NameValuePair(null, signature.TimestampString)
            };

            signature.Hash = HmacUtility.GetHashString(key => new HMACSHA256(key), _secretKey, parameters);
            request.AddHeader("Authorization", "HMACSHA256 " + signature);

            return request;
        }
Beispiel #3
0
        protected override RestRequest PrepareRequest(string path, Method method, Dictionary <string, string> queryParams, string postBody, Dictionary <string, string> headerParams,
                                                      Dictionary <string, string> formParams, Dictionary <string, FileParameter> fileParams, Dictionary <string, string> pathParams)
        {
            var request = base.PrepareRequest(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);

            var signature = new ApiRequestSignature {
                AppId = _appId
            };

            var parameters = new[]
            {
                new NameValuePair(null, _appId),
                new NameValuePair(null, signature.TimestampString)
            };

            signature.Hash = HmacUtility.GetHashString(key => new HMACSHA256(key), _secretKey, parameters);
            request.AddHeader("Authorization", "HMACSHA256 " + signature);

            return(request);
        }
Beispiel #4
0
        public static bool TryParse(string input, out ApiRequestSignature parsedValue)
        {
            parsedValue = null;
            var success = false;

            if (input != null)
            {
                var parts = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 3)
                {
                    if (parts[2].Length == 64)
                    {
                        DateTime timestamp;
                        if (DateTime.TryParseExact(
                            parts[1],
                            "o",
                            CultureInfo.InvariantCulture,
                            DateTimeStyles.AdjustToUniversal,
                            out timestamp))
                        {
                            parsedValue = new ApiRequestSignature
                            {
                                AppId = parts[0],
                                TimestampString = parts[1],
                                Hash = parts[2],
                                Timestamp = timestamp,
                            };
                            success = true;
                        }
                    }
                }
            }

            return success;
        }