Beispiel #1
0
        public string ConstructOAuthHeader(IDictionary <string, string> parameters, string httpMethod, string url, string tokenSecret, string[] excludedKeys = null)
        {
            var sortedParamsBuilder = new StringBuilder();
            var headerBuilder       = new StringBuilder();

            headerBuilder.Append(Constants.OAuthHeaderPrefix);

            foreach (var kv in SortAndEncodeParams(parameters))
            {
                sortedParamsBuilder.AppendFormat("{0}={1}&", kv.Key, kv.Value);
                if (excludedKeys == null || (excludedKeys != null && !excludedKeys.Contains(kv.Key)))
                {
                    headerBuilder.AppendFormat("{0}=\"{1}\", ", kv.Key, kv.Value);
                }
            }

            var sortedParamsString  = sortedParamsBuilder.ToString().TrimEnd('&');
            var signatureBaseString = string.Format("{0}&{1}&{2}", httpMethod, HttpEncoder.Encode(url), HttpEncoder.Encode(sortedParamsString));
            var signature           = Sign(signatureBaseString, Settings.AppSecret + "&" + tokenSecret);

            headerBuilder.AppendFormat("{0}=\"{1}\"", Constants.OAuthSignature, HttpEncoder.Encode(signature));
            return(headerBuilder.ToString());
        }
Beispiel #2
0
        public string ConstructOAuthQueryString(IDictionary <string, string> parameters, string httpMethod, string url, string tokenSecret)
        {
            var sortedParamsBuilder     = new StringBuilder();
            var oAuthQueryStringBuilder = new StringBuilder();

            foreach (var kv in SortAndEncodeParams(parameters))
            {
                sortedParamsBuilder.AppendFormat("{0}={1}&", kv.Key, kv.Value);
                oAuthQueryStringBuilder.AppendFormat("{0}={1}&", kv.Key, kv.Value);
            }

            var sortedParamsString  = sortedParamsBuilder.ToString().TrimEnd('&');
            var signatureBaseString = string.Format("{0}&{1}&{2}", httpMethod, HttpEncoder.Encode(url), HttpEncoder.Encode(sortedParamsString));
            var signature           = Sign(signatureBaseString, Settings.AppSecret + "&" + tokenSecret);

            oAuthQueryStringBuilder.AppendFormat("{0}={1}", Constants.OAuthSignature, HttpEncoder.Encode(signature));
            return(oAuthQueryStringBuilder.ToString());
        }
Beispiel #3
0
        private string ConstructPostBody(IDictionary <string, string> parameters, string url, string accessTokenSecret)
        {
            var sortedParamsBuilder = new StringBuilder();

            foreach (var kv in SortAndEncodeParams(parameters))
            {
                sortedParamsBuilder.Append(string.Format("{0}={1}&", kv.Key, kv.Value));
            }
            // Constructs base string
            var sortedParamsString  = sortedParamsBuilder.ToString().TrimEnd('&');
            var signatureBaseString = string.Format("{0}&{1}&{2}", "POST", HttpEncoder.Encode(url), HttpEncoder.Encode(sortedParamsString));
            var signature           = Sign(signatureBaseString, Settings.AppSecret + "&" + accessTokenSecret);

            var bodyBuilder = new StringBuilder();

            bodyBuilder.Append(sortedParamsBuilder.ToString());
            bodyBuilder.AppendFormat("&{0}={1}", Constants.OAuthSignature, HttpEncoder.Encode(signature));

            return(bodyBuilder.ToString());
        }