public string GetAuthorizationHeader(string uri, string method, ITwitterParameters parameters) { this.OAuthTimestamp = GenerateTimestamp(); this.OAuthNonce = GenerateNonce(); this.OAuthSignature = CalculateSignature(uri, method, parameters); return(string.Format("OAuth {0}", EncodeRequestParameters(this.parameters))); }
private string GetSignatureBase(string url, string method, ITwitterParameters parameters) { var p = new Dictionary <string, string> (); this.parameters.ToList().ForEach(x => { if (!String.IsNullOrEmpty(x.Value) && !x.Key.EndsWith("_secret") && !x.Key.EndsWith("_signature")) { p.Add(x.Key, x.Value); } }); if (parameters != null) { parameters.Queries.ToList().ForEach(x => p.Add(x.Key, x.Value)); } var stringBuilder = new StringBuilder(); p.OrderBy(x => x.Key).ToList().ForEach(x => stringBuilder.AppendFormat("{0}={1}&", UrlEncode(x.Key), UrlEncode(x.Value))); var result = string.Format("{0}&{1}&{2}", method, UrlEncode(url), UrlEncode(stringBuilder.ToString().TrimEnd('&'))); return(result); }
private string CalculateSignature(string uri, string method, ITwitterParameters parameters) { return(Convert.ToBase64String(GetSigningKey().ComputeHash(System.Text.Encoding.ASCII.GetBytes(GetSignatureBase(uri, method, parameters))))); }