public void WhenICreateOAuth2AuthorizationRequestHeaderAuthenticatorWithValue123(string oauthToken) { try { _fluentHttpRequest.AuthenticateUsing(new OAuth2AuthorizationRequestHeaderAuthenticator(oauthToken)); _fluentHttpRequest.GetAuthenticator().Authenticate(_fluentHttpRequest); } catch (Exception ex) { _exception = ex; } }
public void Apply(FluentHttpRequest request, GitHubCredentials credentials) { var userCreds = (GitHubUserCredentials)credentials; request.AuthenticateUsing(new HttpBasicAuthenticator(userCreds.Username, userCreds.Password)); }
public void Apply(FluentHttpRequest request, GitHubCredentials credentials) { var userCreds = (GitHubUserCredentials)credentials; request.AuthenticateUsing(new HttpBasicAuthenticator(userCreds.Username, userCreds.Password)); }
private void GetAllResultsRecursive(string uri, IDictionary<string, object> query, List<string> results, IDictionary<string, object> projectparameters) { if (!IsStarted) return; string json = string.Empty; try { using (var responseSaveStream = new MemoryStream()) { var request = new FluentHttpRequest() .BaseUrl(uri) .Method("GET") .QueryStrings(q => q .Add(query) //add all query strings ) .Proxy(WebRequest.DefaultWebProxy) .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(responseSaveStream)); request.AuthenticateUsing(new OAuth2AuthorizationRequestHeaderBearerAuthenticator(GetFacebookToken())); var ar = request.Execute(); var response = ar.Response; // seek the save stream to beginning. response.SaveStream.Seek(0, SeekOrigin.Begin); json = FluentHttpRequest.ToString(response.SaveStream); Dictionary<string, object> responseobject = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); if (responseobject.ContainsKey(Consts.DATA_KEY) && responseobject[Consts.DATA_KEY].HasValue()) { IList<object> datas = JsonConvert.DeserializeObject<IList<object>>(responseobject[Consts.DATA_KEY].ToString()); if (datas.Count > 0) { for (int i = 0; i < datas.Count; i++) { IDictionary<string, object> resultdic = JsonConvert.DeserializeObject<Dictionary<string, object>>(datas[i].ToString()); //resultdic.Add(Consts.WORDS_KEY, projectparameters); //resultdic.Add(Consts.PROVIDER_KEY, "FaceBook"); if (resultdic.ContainsKey(Consts.DESCRIPTION)) { var message = HttpUtility.HtmlDecode(resultdic[Consts.DESCRIPTION].ToString()); results.Add(message.Substring(0, message.Length < 140 ? message.Length : 140)); } //else if (resultdic.ContainsKey(Consts.MESSAGE)) //{ // var message = HttpUtility.HtmlDecode(resultdic[Consts.MESSAGE].ToString()); // results.Add(message.Substring(0, message.Length < 140 ? message.Length : 140)); // } //results.Add(JsonConvert.SerializeObject(resultdic)); resultdic = null; } foreach (var post in results) { if (!IsStarted) return; string p = string.Empty; if (!string.IsNullOrEmpty(additionalString)) { if (140 - post.Length > additionalString.Length + 1) p = post + " " + additionalString; else p = post.Substring(0, post.Length - additionalString.Length + 1) + " " + additionalString; } _twitterService.SendTweet(new SendTweetOptions { Status = p }); _form.Log(post); System.Threading.Thread.Sleep(2000);//twitter kızmasın } if (responseobject.ContainsKey(Consts.PAGING_KEY) && responseobject[Consts.PAGING_KEY].HasValue()) { IDictionary<string, string> nextprevuri = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseobject[Consts.PAGING_KEY].ToString()); if (nextprevuri.ContainsKey(Consts.NEXT_PAGE_KEY) && nextprevuri[Consts.NEXT_PAGE_KEY].HasValue()) { Uri urim = new Uri(nextprevuri[Consts.NEXT_PAGE_KEY].ToString()); var querystrings = ToDictionary(HttpUtility.ParseQueryString(urim.Query)); urim = null; GetAllResultsRecursive(m_baseUrl, querystrings, results, projectparameters); if (string.IsNullOrEmpty(m_untilValue) && querystrings[Consts.UNTIL_KEY].HasValue()) { m_untilValue = querystrings[Consts.UNTIL_KEY].ToString(); WriteSince(querystrings[Consts.QUERY_KEY].ToString(), m_untilValue); } } } } } request = null; GC.Collect(); } } catch (Exception ex) { throw; } }
internal virtual FluentHttpRequest PrepareRequest(GithubApiVersion version, string method, string path, object parameters, Stream responseStream) { var request = new FluentHttpRequest() .ResourcePath(path) .Method(method) .Proxy(Proxy) .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(responseStream)); request.BaseUrl(version == GithubApiVersion.V3 ? "https://api.github.com" : "https://github.com/api/v2/json"); string bearerToken = null; IDictionary<string, object> dictionaryParameters = null; if (parameters is IDictionary<string, object>) dictionaryParameters = (IDictionary<string, object>)parameters; // give priority to bearer_token then access_token specified in parameters. if (dictionaryParameters != null) { if (dictionaryParameters.ContainsKey("bearer_token")) { bearerToken = dictionaryParameters["bearer_token"].ToString(); dictionaryParameters.Remove(bearerToken); } else if (dictionaryParameters.ContainsKey("access_token")) { bearerToken = dictionaryParameters["access_token"].ToString(); dictionaryParameters.Remove(bearerToken); } } if (Authentication != null) { if (string.IsNullOrEmpty(bearerToken) && Authentication is GithubOAuthAuthenticator) { var oauth2 = (GithubOAuthAuthenticator)Authentication; bearerToken = oauth2.AccessToken; } if (string.IsNullOrEmpty(bearerToken)) { if (Authentication is GithubBasicAuthenticator) { var basicAuth = (GithubBasicAuthenticator)Authentication; request.AuthenticateUsing(new HttpBasicAuthenticator(basicAuth.Username, basicAuth.Password)); } else { throw new NotSupportedException("Authentication not supported."); } } else { request.AuthenticateUsing(new OAuth2AuthorizationRequestHeaderBearerAuthenticator(bearerToken)); } } if (method.Equals("GET", StringComparison.OrdinalIgnoreCase)) { // for GET, all parameters goes as querystring request.QueryStrings(qs => qs.Add(dictionaryParameters)); } else { return request .Headers(h => h.Add("Content-Type", "application/json")) .Body(b => { if (parameters != null) b.Append(JsonSerializer.Current.SerializeObject(parameters)); }); } return request; }
public void WhenAuthenticateUsingOAuth2AuthorizationRequestHeaderAuthenticatorWithAccessToken123(string oauthToken) { _fluentHttpRequest.AuthenticateUsing(new OAuth2AuthorizationRequestHeaderAuthenticator(oauthToken)); _fluentHttpRequest.GetAuthenticator().Authenticate(_fluentHttpRequest); }