コード例 #1
0
        private static string GenerateSignatureBase(HttpMethod httpMethod, string normalizedUrl, string normalizedParameters)
        {
            StringBuilder signatureBase = new StringBuilder();

            signatureBase.AppendFormat("{0}&", httpMethod.ToString().ToUpperInvariant());
            signatureBase.AppendFormat("{0}&", ZAppHelper.URLEncode(normalizedUrl));
            signatureBase.AppendFormat("{0}", ZAppHelper.URLEncode(normalizedParameters));
            return(signatureBase.ToString());
        }
コード例 #2
0
        private static string GenerateSignature(string signatureBase, string consumerSecret, string userSecret = null)
        {
            using (HMACSHA1 hmacsha1 = new HMACSHA1())
            {
                string key = string.Format("{0}&{1}", Uri.EscapeDataString(consumerSecret),
                                           string.IsNullOrEmpty(userSecret) ? string.Empty : Uri.EscapeDataString(userSecret));

                hmacsha1.Key = Encoding.ASCII.GetBytes(key);

                byte[] dataBuffer = Encoding.ASCII.GetBytes(signatureBase);
                byte[] hashBytes  = hmacsha1.ComputeHash(dataBuffer);

                string signature = Convert.ToBase64String(hashBytes);

                return(ZAppHelper.URLEncode(signature));
            }
        }
コード例 #3
0
        public static string GetAuthorizationURL(string requestTokenResponse, OAuthInfo oauth, string authorizeURL, string callback = null)
        {
            string url = null;

            NameValueCollection args = HttpUtility.ParseQueryString(requestTokenResponse);

            if (args[ParameterToken] != null)
            {
                oauth.AuthToken = args[ParameterToken];
                url             = string.Format("{0}?{1}={2}", authorizeURL, ParameterToken, oauth.AuthToken);

                if (!string.IsNullOrEmpty(callback))
                {
                    url += string.Format("&{0}={1}", ParameterCallback, ZAppHelper.URLEncode(callback));
                }

                if (args[ParameterTokenSecret] != null)
                {
                    oauth.AuthSecret = args[ParameterTokenSecret];
                }
            }

            return(url);
        }
コード例 #4
0
 private static string NormalizeParameters(Dictionary <string, string> parameters)
 {
     return(string.Join("&", parameters.OrderBy(x => x.Key).ThenBy(x => x.Value).Select(x => x.Key + "=" + ZAppHelper.URLEncode(x.Value)).ToArray()));
 }