public virtual WebResponse ExecuteFeed(string feedURL, TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary<string, string> headers = null) { if (AuthenticationStrategy != null) return AuthenticationStrategy.ExecuteFeed(feedURL, (IProvider)this, GetConnectionToken(), transportMethod, content, headers); else throw new NotImplementedException("This method is not implemented!;"); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return AuthenticationStrategy.ExecuteFeed(feedUrl, this, SocialAuthUser.GetCurrentUser().GetConnection(ProviderType).GetConnectionToken(), transportMethod); }
public abstract WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod);
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return(AuthenticationStrategy.ExecuteFeed(feedUrl, this, SocialAuthUser.GetCurrentUser().GetConnection(ProviderType).GetConnectionToken(), transportMethod)); }
public static WebResponse ExecuteFeed(string feedUrl, string accessToken, string tokenSecret, TRANSPORT_METHOD transportMethod) { MySpaceWrapper wrapper = new MySpaceWrapper(); return wrapper.AuthenticationStrategy.ExecuteFeed(feedUrl, wrapper, new Token() { AccessToken = accessToken, TokenSecret = tokenSecret }, transportMethod); }
public void RequestForAccessToken(TRANSPORT_METHOD method = TRANSPORT_METHOD.GET) { if (method != TRANSPORT_METHOD.GET && method != TRANSPORT_METHOD.POST) throw new OAuthException("Invalid Verb used for requesting AccessToken. Supported verbs are GET/POST."); UriBuilder ub = new UriBuilder(provider.AccessTokenEndpoint); //logger.LogAuthorizationRequest(ub.ToString()); HttpWebRequest request; if (method == TRANSPORT_METHOD.POST) { request = (HttpWebRequest)WebRequest.Create(ub.ToString()); string postData = "code=" + ConnectionToken.Code; postData += ("&client_id=" + provider.Consumerkey); postData += ("&client_secret=" + provider.Consumersecret); postData += ("&redirect_uri=" + ConnectionToken.ProviderCallbackUrl); postData += ("&grant_type=authorization_code"); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. } else { ub.SetQueryparameter("client_id", provider.Consumerkey); ub.SetQueryparameter("client_secret", provider.Consumersecret); ub.SetQueryparameter("code", ConnectionToken.Code); ub.SetQueryparameter("redirect_uri", ConnectionToken.ProviderCallbackUrl); ub.SetQueryparameter("grant_type", "authorization_code"); request = (HttpWebRequest)WebRequest.Create(ub.ToString()); request.Method = "POST"; } try { logger.Debug("Requesting Access Token at " + ub.ToString()); using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse()) using (Stream responseStream = webResponse.GetResponseStream()) using (StreamReader reader = new StreamReader(responseStream)) { string authToken = reader.ReadToEnd(); HandleAccessTokenResponse(authToken); } } catch (Exception ex) { logger.Error(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex); throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex); } }
public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary<string, string> headers = null) { HttpWebRequest request; request = (HttpWebRequest)HttpWebRequest.Create(feedURL); request.ServicePoint.Expect100Continue = false; request.Method = transportMethod.ToString(); //if headers are specified, set/append them if (headers != null) { foreach (var header in headers) { switch (header.Key) { case "ContentLength": { request.ContentLength = long.Parse(header.Value); break; } case "ContentType": { request.ContentType = header.Value; break; } default: { request.Headers[header.Key] = header.Value; break; } } } } if (request.ContentLength == 0 & content.Length > 0) request.ContentLength = content.Length; request.GetRequestStream().Write(content, 0, content.Length); WebResponse wr = null; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex); } return wr; }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { throw new NotImplementedException(); }
/// <summary> /// Generate Signature /// </summary> /// <param name="requestURL"></param> /// <param name="oauthParameters"></param> /// <param name="consumerKey"></param> /// <param name="consumerSecret"></param> /// <param name="signatureType"></param> /// <param name="httpMethod"></param> /// <param name="tokenSecret"></param> /// <returns></returns> public string GenerateSignature(Uri requestURL, QueryParameters oauthParameters, string consumerKey, string consumerSecret, SIGNATURE_TYPE signatureType, TRANSPORT_METHOD httpMethod, string tokenSecret) { QueryParameters tmpOauthParameters = new QueryParameters(); foreach (var param in oauthParameters) { if (param.Value.ToLower().Contains("http://") || param.Value.ToLower().Contains("https://")) tmpOauthParameters.Add(new QueryParameter(param.Key, Utility.UrlEncode(param.Value))); else tmpOauthParameters.Add(new QueryParameter(param.Key, param.Value)); } tmpOauthParameters[OAuthSignatureMethodKey] = ParseSignatureEnum(signatureType); string signature = ""; StringBuilder signatureBase = new StringBuilder(); //1. URL encode and process Request URL string normalizedRequestUrl; normalizedRequestUrl = string.Format("{0}://{1}", requestURL.Scheme, requestURL.Host); if (!((requestURL.Scheme == "http" && requestURL.Port == 80) || (requestURL.Scheme == "https" && requestURL.Port == 443))) { normalizedRequestUrl += ":" + requestURL.Port; } normalizedRequestUrl += requestURL.AbsolutePath; normalizedRequestUrl = Utility.UrlEncode(normalizedRequestUrl); //2. URL Encode callbackUrl (if present) //if (tmpOauthParameters.HasName(OAuthCallbackKey)) // tmpOauthParameters[OAuthCallbackKey] = Utility.UrlEncode(tmpOauthParameters[OAuthCallbackKey]); //tmpOauthParameters["scope"] = Utility.UrlEncode(tmpOauthParameters["scope"]); foreach (var p in Utility.GetQuerystringParameters(requestURL.ToString())) tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value))); //following works for Twitter with spaces //tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value))); //3. Perform Lexographic Sorting tmpOauthParameters.Sort(); //4. Generate Signature Base signatureBase.AppendFormat("{0}&", httpMethod.ToString().ToUpper()); signatureBase.AppendFormat("{0}&", normalizedRequestUrl); signatureBase.AppendFormat("{0}", Utility.UrlEncode(tmpOauthParameters.ToString())); string sbase = signatureBase.ToString(); logger.Debug("signature base:" + sbase); //5. Generate Signature switch (signatureType) { case SIGNATURE_TYPE.PLAINTEXT: { signature = Utility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret)); break; } case SIGNATURE_TYPE.HMACSHA1: { HMACSHA1 hmacsha1 = new HMACSHA1(); hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : tokenSecret)); signature = GenerateSignatureUsingHash(sbase, hmacsha1); logger.Debug("HMACSHA1 signature:" + signature); break; } default: throw new ArgumentException("Unknown signature type", "signatureType"); } return signature; }
public abstract WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod);
public virtual WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary<string, string> headers = null) { throw new NotImplementedException(); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return(AuthenticationStrategy.ExecuteFeed(feedUrl, this, ConnectionToken, transportMethod)); }
public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod) { string signature = ""; OAuthHelper oauthHelper = new OAuthHelper(); QueryParameters oauthParams = new QueryParameters(); oauthParams.Add("oauth_consumer_key", provider.Consumerkey); oauthParams.Add("oauth_nonce", oauthHelper.GenerateNonce()); oauthParams.Add("oauth_signature_method", provider.SignatureMethod.ToString()); oauthParams.Add("oauth_timestamp", oauthHelper.GenerateTimeStamp()); oauthParams.Add("oauth_token", connectionToken.AccessToken); oauthParams.Add("oauth_version", "1.0"); ////1. Generate Signature signature = oauthHelper.GenerateSignature(new Uri(feedURL), oauthParams, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, TRANSPORT_METHOD.GET, connectionToken.TokenSecret); oauthParams.Add("oauth_signature", signature); //3.Connect and Execute Feed HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(feedURL); request.Method = transportMethod.ToString(); request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParams)); //request.ContentType = "application/atom+xml"; request.ContentLength = 0; WebResponse wr; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); } return(wr); }
public static WebResponse ExecuteFeed(string feedUrl, string accessToken, string tokenSecret, TRANSPORT_METHOD transportMethod) { MySpaceWrapper wrapper = new MySpaceWrapper(); return(wrapper.AuthenticationStrategy.ExecuteFeed(feedUrl, wrapper, new Token() { AccessToken = accessToken, TokenSecret = tokenSecret }, transportMethod)); }
public static WebResponse ExecuteFeed(string feedUrl, string accessToken, TRANSPORT_METHOD transportMethod) { MSNWrapper msn = new MSNWrapper(); return msn.AuthenticationStrategy.ExecuteFeed(feedUrl, msn, new Token() { AccessToken = accessToken }, transportMethod); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return AuthenticationStrategy.ExecuteFeed(feedUrl, this, ConnectionToken, transportMethod); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { logger.Debug("Calling execution of " + feedUrl); return AuthenticationStrategy.ExecuteFeed(feedUrl, this, ConnectionToken, transportMethod); }
public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod) { string signature = ""; OAuthHelper oauthHelper = new OAuthHelper(); QueryParameters oauthParams = new QueryParameters(); oauthParams.Add("oauth_consumer_key", provider.Consumerkey); oauthParams.Add("oauth_nonce", oauthHelper.GenerateNonce()); oauthParams.Add("oauth_signature_method", provider.SignatureMethod.ToString()); oauthParams.Add("oauth_timestamp", oauthHelper.GenerateTimeStamp()); oauthParams.Add("oauth_token", connectionToken.AccessToken); oauthParams.Add("oauth_version", "1.0"); ////1. Generate Signature signature = oauthHelper.GenerateSignature(new Uri(feedURL), oauthParams, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, TRANSPORT_METHOD.GET, connectionToken.TokenSecret); oauthParams.Add("oauth_signature", signature); //3.Connect and Execute Feed HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(feedURL); request.Method = transportMethod.ToString(); request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParams)); //request.ContentType = "application/atom+xml"; request.ContentLength = 0; WebResponse wr; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); } return wr; }
public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod) { UriBuilder ub; /******** retrieve standard Fields ************/ ub = new UriBuilder(feedURL); ub.SetQueryparameter(AccessTokenQueryParameterKey, connectionToken.AccessToken); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ub.ToString()); request.Method = transportMethod.ToString(); //logger.LogContactsRequest(ub.ToString()); WebResponse wr; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex); } return wr; }
///// <summary> ///// Execute data feed with current or specified provider ///// </summary> ///// <param name="feedUrl"></param> ///// <param name="transportMethod"></param> ///// <returns></returns> public WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod, PROVIDER_TYPE providerType = PROVIDER_TYPE.NOT_SPECIFIED, byte[] content = null, Dictionary<string, string> headers = null) { IProvider provider = null; //provider is not specified explicitly. Pick connected provider. if (providerType == PROVIDER_TYPE.NOT_SPECIFIED) { if (SessionManager.IsConnected) provider = SessionManager.GetCurrentConnection(); } else //provider explicitly specified { if (SessionManager.IsConnectedWith(providerType)) provider = ProviderFactory.GetProvider(providerType); } if (provider == null) throw new InvalidSocialAuthConnectionException(providerType); //Call ExecuteFeed WebResponse response; if (headers == null && content == null) response = provider.ExecuteFeed(feedUrl, transportMethod); else response = provider.ExecuteFeed(feedUrl, transportMethod, content, headers); return response; }
//public static WebResponse ExecuteFeed(string feedURL, TRANSPORT_METHOD transportMethod) //{ // UriBuilder ub; // /******** retrieve standard Fields ************/ // ub = new UriBuilder(feedURL); // //if (oauthParameters != null) // // foreach (var param in oauthParameters) // // ub.SetQueryparameter(param.Name, param.Value); // HttpWebRequest webRequest = null; // //StreamWriter requestWriter = null; // webRequest = System.Net.WebRequest.Create(feedURL) as HttpWebRequest; // webRequest.Method = transportMethod.ToString(); // webRequest.Timeout = 20000; // if (transportMethod == TRANSPORT_METHOD.POST) // { // webRequest.ServicePoint.Expect100Continue = false; // webRequest.ContentType = "application/x-www-form-urlencoded"; // //requestWriter = new StreamWriter(webRequest.GetRequestStream()); // //try // //{ // // requestWriter.Write(string.Empty); // //} // //catch // //{ // // throw; // //} // //finally // //{ // // requestWriter.Close(); // // requestWriter = null; // //} // } // WebResponse wr; // try // { // wr = (WebResponse)webRequest.GetResponse(); // } // catch (Exception ex) // { // throw new OAuthException("An Error occurred while executing " + feedURL + "!", ex); // } // return wr; //} public static WebResponse ExecuteFeed(string feedURL, TRANSPORT_METHOD transportMethod) { UriBuilder ub; /******** retrieve standard Fields ************/ ub = new UriBuilder(feedURL); //if (oauthParameters != null) // foreach (var param in oauthParameters) // ub.SetQueryparameter(param.Name, param.Value); HttpWebRequest webRequest = null; //StreamWriter requestWriter = null; webRequest = System.Net.WebRequest.Create(feedURL) as HttpWebRequest; webRequest.Method = transportMethod.ToString(); webRequest.Timeout = 20000; if (transportMethod == TRANSPORT_METHOD.POST) { webRequest.ServicePoint.Expect100Continue = false; webRequest.ContentType = "application/x-www-form-urlencoded"; //requestWriter = new StreamWriter(webRequest.GetRequestStream()); //try //{ // requestWriter.Write(string.Empty); //} //catch //{ // throw; //} //finally //{ // requestWriter.Close(); // requestWriter = null; //} } WebResponse wr; try { wr = (WebResponse)webRequest.GetResponse(); } catch (Exception ex) { throw new OAuthException("An Error occurred while executing " + feedURL + "!", ex); } return wr; }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { logger.Debug("Calling execution of " + feedUrl); return AuthenticationStrategy.ExecuteFeed(feedUrl, this, SocialAuthUser.GetConnection(this.ProviderType).GetConnectionToken(), transportMethod); }