public static string GenerateHeader(Uri uri, String consumerKey, String consumerSecret, String token, String tokenSecret, String httpMethod) { OAuthUtil oauthUtil = new OAuthUtil(); string timeStamp = oauthUtil.GenerateTimeStamp(); string nonce = oauthUtil.GenerateNonce(); string normalizedUrl; string normalizedRequestParameters; string signature = oauthUtil.GenerateSignature(uri, consumerKey, consumerSecret, token, tokenSecret, httpMethod.ToUpper(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters); signature = System.Web.HttpUtility.UrlEncode(signature); StringBuilder sb = new StringBuilder(); sb.Append("Authorization: OAuth realm=\"\",oauth_version=\"1.0\","); sb.AppendFormat("oauth_nonce=\"{0}\",", nonce); sb.AppendFormat("oauth_timestamp=\"{0}\",", timeStamp); sb.AppendFormat("oauth_consumer_key=\"{0}\",", consumerKey); if (!String.IsNullOrEmpty(token)) { token = System.Web.HttpUtility.UrlEncode(token); sb.AppendFormat("oauth_token=\"{0}\",", token); } sb.Append("oauth_signature_method=\"HMAC-SHA1\","); sb.AppendFormat("oauth_signature=\"{0}\"", signature); return(sb.ToString()); }
public static string GenerateHeader(Uri uri, String consumerKey, String consumerSecret, String token, String tokenSecret, String httpMethod) { OAuthUtil oauthUtil = new OAuthUtil(); string timeStamp = oauthUtil.GenerateTimeStamp(); string nonce = oauthUtil.GenerateNonce(); string normalizedUrl; string normalizedRequestParameters; string signature = oauthUtil.GenerateSignature(uri, consumerKey, consumerSecret, token, tokenSecret, httpMethod.ToUpper(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters); signature = System.Web.HttpUtility.UrlEncode(signature); StringBuilder sb = new StringBuilder(); sb.Append("Authorization: OAuth realm=\"\",oauth_version=\"1.0\","); sb.AppendFormat("oauth_nonce=\"{0}\",", nonce); sb.AppendFormat("oauth_timestamp=\"{0}\",", timeStamp); sb.AppendFormat("oauth_consumer_key=\"{0}\",", consumerKey); if (!String.IsNullOrEmpty(token)) { token = System.Web.HttpUtility.UrlEncode(token); sb.AppendFormat("oauth_token=\"{0}\",", token); } sb.Append("oauth_signature_method=\"HMAC-SHA1\","); sb.AppendFormat("oauth_signature=\"{0}\"", signature); return sb.ToString(); }
public static string GenerateHeader(Uri uri, String consumerKey, String consumerSecret, String token, String tokenSecret, String httpMethod) { OAuthUtil oauthUtil = new OAuthUtil(); string timeStamp = oauthUtil.GenerateTimeStamp(); string nonce = oauthUtil.GenerateNonce(); string signature = oauthUtil.GenerateSignature(uri, consumerKey, consumerSecret, token, tokenSecret, httpMethod.ToUpper(), timeStamp, nonce); StringBuilder sb = new StringBuilder(); sb.Append("Authorization: OAuth oauth_version=\"1.0\","); sb.AppendFormat("oauth_nonce=\"{0}\",", EncodingPerRFC3986(nonce)); sb.AppendFormat("oauth_timestamp=\"{0}\",", EncodingPerRFC3986(timeStamp)); sb.AppendFormat("oauth_consumer_key=\"{0}\",", EncodingPerRFC3986(consumerKey)); if (!String.IsNullOrEmpty(token)) { sb.AppendFormat("oauth_token=\"{0}\",", EncodingPerRFC3986(token)); } sb.Append("oauth_signature_method=\"HMAC-SHA1\","); sb.AppendFormat("oauth_signature=\"{0}\"", EncodingPerRFC3986(signature)); return(sb.ToString()); }
/// <summary> /// Generates an OAuth header. /// </summary> /// <param name="uri">The URI of the request</param> /// <param name="consumerKey">The consumer key</param> /// <param name="consumerSecret">The consumer secret</param> /// <param name="token"></param> /// <param name="httpMethod">The http method</param> /// <returns>The OAuth authorization header</returns> private static string GenerateHeader(Uri uri, String consumerKey, String consumerSecret, string token, String httpMethod) { Contract.Assume(!string.IsNullOrEmpty(token)); //token = System.Web.HttpContext.Current.Server.UrlEncode(token); //string accessecret = OAuthUtil oauthUtil = new OAuthUtil(); string timeStamp = oauthUtil.GenerateTimeStamp(); string nonce = oauthUtil.GenerateNonce(); string normalizedUrl; string normalizedRequestParameters; string signature = oauthUtil.GenerateSignature(uri, consumerKey, consumerSecret, UrlEncode(token), MvcApplication.GoogleTokenManager.GetTokenSecret(token), httpMethod.ToUpper(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters); signature = UrlEncode(signature); //StringBuilder sb = new StringBuilder(); //sb.Append("Authorization: OAuth realm=\"\",oauth_version=\"1.0\","); //sb.AppendFormat("oauth_nonce=\"{0}\",", nonce); //sb.AppendFormat("oauth_timestamp=\"{0}\",", timeStamp); //sb.AppendFormat("oauth_consumer_key=\"{0}\",", consumerKey); //sb.Append("oauth_signature_method=\"HMAC-SHA1\","); //sb.AppendFormat("oauth_signature=\"{0}\"", signature); StringBuilder sb = new StringBuilder(); sb.Append("Authorization: OAuth oauth_version=\"1.0\","); sb.AppendFormat("oauth_nonce=\"{0}\",", nonce); sb.AppendFormat("oauth_timestamp=\"{0}\",", timeStamp); sb.AppendFormat("oauth_consumer_key=\"{0}\",", consumerKey); sb.Append("oauth_signature_method=\"HMAC-SHA1\","); sb.AppendFormat("oauth_token=\"{0}\",", UrlEncode(token)); // sb.AppendFormat("oauth_token_secret=\"{0}\",", MvcApplication.GoogleTokenManager.GetTokenSecret(State.GoogleAccessToken)); sb.AppendFormat("oauth_signature=\"{0}\"", signature); return sb.ToString(); }