/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="command"></param> /// <returns></returns> public static SignatureInfo GenerateSignature(Uri url, GetRequestTokenCommand command) { return(GenerateSignature(url, command, OAuthSignatureTypes.HMACSHA1)); }
private HttpRequestCommand CreateHttpClientQueryStringMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary<String, String> queryString) { var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName); Dictionary<String, String> pp = OAuth1Client.GenerateParameters(cm); foreach (var p in queryString) { pp.Add(p.Key, p.Value); } var u = new Uri(HttpClient.CreateQueryString(url, pp, OAuth1Client.UrlEncode)); SignatureInfo si = GenerateSignature(u, cm); pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature)); HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, pp, HttpClient.UrlEncode)); cl.MethodName = methodName; return cl; }
private HttpRequestCommand CreateHttpClientRequestHeaderMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary<String, String> queryString) { var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret, token, tokenSecret, methodName); Dictionary<String, String> pp = OAuth1Client.GenerateParameters(cm); var u = new Uri(HttpClient.CreateQueryString(url, queryString, OAuth1Client.UrlEncode)); SignatureInfo si = GenerateSignature(u, cm); pp.Add("oauth_signature", OAuth1Client.UrlEncode(si.Signature)); HttpRequestCommand cl = new HttpRequestCommand(HttpClient.CreateQueryString(url, queryString, HttpClient.UrlEncode)); cl.MethodName = methodName; cl.Headers[HttpRequestHeader.Authorization] = this.CreateOAuthHeader(pp); return cl; }
/// <summary> /// /// </summary> /// <param name="command"></param> /// <returns></returns> public static Dictionary<String, String> GenerateParameters(GetRequestTokenCommand command) { var cm = command; Dictionary<String, String> result = new Dictionary<String, String>(); result.Add("oauth_consumer_key", cm.ConsumerKey); result.Add("oauth_signature_method", "HMAC-SHA1"); result.Add("oauth_timestamp", cm.TimeStamp); result.Add("oauth_nonce", cm.Nonce); result.Add("oauth_version", "1.0"); if (String.IsNullOrEmpty(cm.Token) == false) { result.Add("oauth_token", cm.Token); } return result; }