Beispiel #1
0
        private string GenerateSignature(Uri uri, MethodType methodType, Token token, IEnumerable<Parameter> parameters)
        {
            var hmacKeyBase = ConsumerSecret.UrlEncode() + "&" + ((token == null) ? "" : token.Secret).UrlEncode();
            using (var hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(hmacKeyBase)))
            {
                var stringParameter = parameters.OrderBy(p => p.Key)
                   .ThenBy(p => p.Value)
                   .ToQueryParameter();
                var signatureBase = methodType.ToUpperString() +
                    "&" + uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped).UrlEncode() +
                    "&" + stringParameter.UrlEncode();

                var hash = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(signatureBase));
                return Convert.ToBase64String(hash).UrlEncode();
            }
        }
        private string GenerateSignature(Uri uri, MethodType methodType, Token token, IEnumerable <Parameter> parameters)
        {
            var hmacKeyBase = ConsumerSecret.UrlEncode() + "&" + ((token == null) ? "" : token.Secret).UrlEncode();

            using (var hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(hmacKeyBase)))
            {
                var stringParameter = parameters.OrderBy(p => p.Key)
                                      .ThenBy(p => p.Value)
                                      .ToQueryParameter();
                var signatureBase = methodType.ToUpperString() +
                                    "&" + uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped).UrlEncode() +
                                    "&" + stringParameter.UrlEncode();

                var hash = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(signatureBase));
                return(Convert.ToBase64String(hash).UrlEncode());
            }
        }
Beispiel #3
0
        protected virtual WebRequest CreateWebRequest()
        {
            var requestUrl = (MethodType == OAuth.MethodType.Get) ? Url + "?" + Parameters.ToQueryParameter() : Url;
            var req        = (HttpWebRequest)WebRequest.Create(requestUrl);

#if WINDOWS_PHONE
            req.AllowReadStreamBuffering = false;
#endif
            req.Headers[HttpRequestHeader.Authorization] = this.AuthorizationHeader;
            req.Method = MethodType.ToUpperString();
            if (MethodType == OAuth.MethodType.Post)
            {
                req.ContentType = "application/x-www-form-urlencoded";
            }
            if (ApplyBeforeRequest != null)
            {
                ApplyBeforeRequest(req);
            }

            return(req);
        }