Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public override void UpdateParamsForAuth(Dictionary<string, string> queryParams, Dictionary<string, string> headerParams, string[] authSettings)
        {
            base.UpdateParamsForAuth(queryParams, headerParams, authSettings);

            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);
            headerParams["Authorization"] = "HMACSHA256 " + signature;
        }
Ejemplo n.º 3
0
        public override void UpdateParamsForAuth(Dictionary <string, string> queryParams, Dictionary <string, string> headerParams, string[] authSettings)
        {
            base.UpdateParamsForAuth(queryParams, headerParams, authSettings);

            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);
            headerParams["Authorization"] = "HMACSHA256 " + signature;
        }
Ejemplo n.º 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;
        }