Exemple #1
0
        private Dictionary <string, string> GetOauth1Params(OauthParams options, Dictionary <string, string> data)
        {
            var key    = options.Key;
            var token  = options.Token;
            var secret = options.ConsumerSecret;
            var method = options.Method;
            var url    = options.Url;

            var parameter = new Dictionary <string, string>();

            parameter.Add("oauth_consumer_key", key);
            parameter.Add("oauth_signature_method", "HMAC-SHA1");
            parameter.Add("oauth_timestamp", Convert.ToInt64((DateTime.UtcNow - UnixEpoch).TotalSeconds).ToString());
            //epoch秒
            parameter.Add("oauth_nonce", NonceRandom.Next(123400, 9999999).ToString());
            parameter.Add("oauth_version", "1.0");
            if (!string.IsNullOrEmpty(token))
            {
                parameter.Add("oauth_token", token);
            }
            foreach (var kv in data)
            {
                var k = kv.Key;
                var v = kv.Value;
                parameter.Add(k, v);
            }
            parameter.Add("oauth_signature", CreateSignature(secret, method, new Uri(url), parameter));
            return(parameter);
        }
Exemple #2
0
        private string GetOauth1Header(OauthParams options, Dictionary <string, string> data)
        {
            var           @params = GetOauth1Params(options, data);
            StringBuilder sb      = new StringBuilder();

            foreach (var kv in @params)
            {
                var k = kv.Key;
                var v = kv.Value;
                sb.AppendFormat("{0}=\"{1}\",", k, UrlEncode(v));
            }
            return(sb.ToString());
        }