public void AuthenticateRequest(IRestRequest request) { foreach (var cookie in GetAuthCookies()) { request.AddCookie(cookie.Name, cookie.Value); } }
private void AddCookieValues(IRestRequest request, IDictionary <string, string> args) { MapProperites( MappingType.Cookie, String.IsNullOrWhiteSpace, args, (name, value) => request.AddCookie(name, value)); }
private void AddCookieValues(IRestRequest request, IDictionary<string, string> args) { MapProperites( MappingType.Cookie, String.IsNullOrWhiteSpace, args, (name, value) => request.AddCookie(name, value)); }
partial void InterceptRequest(IRestRequest request) { if (cookie == null) { return; } Console.WriteLine("Add cookie to request: " + cookie); request.AddCookie(CookieKey, cookie); }
public static IRestRequest AddCookies(this IRestRequest source, IEnumerable <Cookie> cookies) { foreach (var cookie in cookies) { source.AddCookie(cookie.Name, cookie.Value); } return(source); }
private Task <T> SSOIDRequest <T>(IRestRequest request) where T : BetfairBaseJsonRequest { if (string.IsNullOrWhiteSpace(SSOID)) { throw new ArgumentException("Empty SSOID"); } request.AddCookie("ssoid", SSOID); return(RequestAsync <T>(request)); }
public static void SetCoolCookies(this IRestRequest restRequest, ICoolQApi api) { var cookies = api.GetCookies(); foreach (var s in cookies.Split(';').Select(x => x.Trim())) { var nameValue = s.Split('='); restRequest.AddCookie(nameValue[0], nameValue[1]); } }
private static void AddCookie(CookieCollection cookies, IRestRequest request, string name) { var cookie = cookies.FirstOrDefault(x => x.Name.Equals(name)); if (cookie is null) { return; } request.AddCookie(name, cookie.Value); }
public async Task <bool> PostFileAsync(RequestInfoEventArgs requestInfo, Stream stream) { IRestClient client = CreateRestClient(); client.CookieContainer = new CookieContainer(); var heartBeat = new RestRequest(_config.PingResource, Method.GET); var heartBeatUrl = client.BuildUri(heartBeat); // For debugging purposes. _logger.LogDebug($"Will perform a GET to Heartbeat-endpoint using {heartBeatUrl}."); var heartBeatResponse = await client.ExecuteGetAsync(heartBeat); if (!heartBeatResponse.IsSuccessful) { // Possible error handling here. // If you are unable to ping the heartbeat endpoint there's probably // something wrong with the certificate. _logger.LogWarning("Get to Heartbeat-endpoint was not successful. Will abort."); return(false); } _logger.LogDebug("Get to Heartbeat-endpoint was successful."); var cookies = client.CookieContainer.GetCookies(new Uri(_config.BaseUrl)); IRestRequest request = CreateFileUploadRequest(requestInfo, stream); foreach (Cookie restResponseCookie in cookies) { request.AddCookie(restResponseCookie.Name, restResponseCookie.Value); } var url = client.BuildUri(request); _logger.LogInformation($"Posting file to: {url}"); var response = await client.ExecutePostAsync <FileUploadResponse>(request); if (response.StatusCode == HttpStatusCode.OK && response.Data != null) { _logger.LogInformation($"File successfully posted. Thank you. The id for your deliveryId is: {response.Data.DeliveryId}."); // You might want to return the deliveryId for further processing. // For the moment we simply return true to indicate success. return(true); } _logger.LogInformation($"Post failed. Response: {response.ErrorMessage}"); return(false); }
/// <summary> /// It adds UserId/AuthToken pattern to request url /// </summary> /// <param name="client">RestClient object</param> /// <param name="request">RestRequest object</param> public void Authenticate(IRestClient client, IRestRequest request) { string authPart = string.Format("{0:d}/{1:s}", Credentials.User.UserId, Credentials.AuthToken); // If it's first request then we send authentication token if (string.IsNullOrEmpty(Credentials.SessionId)) { request.Resource = string.Format("{0:s}/{1:s}", request.Resource, authPart); } else { // If it's next request then we send session cookie instead of authentication token request.AddCookie(InfoReminderWebApi.SessionCookieName, Credentials.SessionId); } }
public void Authenticate(IRestClient client, IRestRequest request) { if (AuthCookies.Count == 0) { var authClient = new RestClient { BaseUrl = _baseUrl }; var loginRequest = new RestRequest(Method.POST) { Resource = "auth/login", RequestFormat = DataFormat.Json }; loginRequest.AddBody(new Web.ViewModels.AuthCredential { Username = _userName, Password = _password }); var loginResponse = authClient.Execute<dynamic>(loginRequest); AuthCookies = loginResponse.Cookies; } foreach (var restResponseCookie in AuthCookies) { request.AddCookie(restResponseCookie.Name, restResponseCookie.Value); } }
public async Task <string> SteamRequestRawAsync(IRestRequest request, bool withAuth, Proxy proxy = null) { if (withAuth && Auth.CookieCollection != null) { foreach (Cookie cookie in Auth.CookieCollection) { request.AddCookie(cookie.Name, cookie.Value); } } var client = proxy != null?CreateClient(SteamEndpoints.BASE_HOST_URL, DefaultUserAgent) : _client; var response = await RequestRawAsync(client, request, proxy); if (withAuth) { Auth.SetCookies(response.Cookies); } return(response.Content); }
public Given Cookie(string name, string value) { request.AddCookie(name, value); return(this); }
public void Authenticate(IRestClient client, IRestRequest request) { if (User == null) throw new NotAuthorizedException("No user"); if (!User.Identity.IsAuthenticated) throw new NotAuthorizedException("Not logged in"); var identity = User.Identity as FormsIdentity; if (identity == null) throw new NotSupportedException("User.Identity must be a FormsIdentity"); var ticket = identity.Ticket; var cookieData = JsonConvert.DeserializeObject<Dictionary<string, string>>(ticket.UserData); foreach (var item in cookieData) request.AddCookie(item.Key, item.Value); }
void Authorize(IRestRequest request) { if (String.IsNullOrWhiteSpace(AuthCookie)) return; request.AddCookie(OhbCookies.AuthCookie, AuthCookie); }
public IRestRequest AddCookie(string name, string value) { return(_restRequest.AddCookie(name, value)); }
private void AddRequestCookies(IRestRequest request) { request.AddCookie("SC_ANALYTICS_GLOBAL_COOKIE", ConfigurationManager.AppSettings["ScAnalyticsGlobalCookie"]); }