private async Task<GetLoginPageResult> GetLoginPage() { var result = new GetLoginPageResult(); var queryParameter = new[] { new KeyValuePair<string, string>("locale", "en_US"), new KeyValuePair<string, string>("state", "bfh"), new KeyValuePair<string, string>("redirect_uri", "https://battlelog.battlefield.com/sso/?tokentype=code"), new KeyValuePair<string, string>("response_type", "code"), new KeyValuePair<string, string>("client_id", "battlelog"), new KeyValuePair<string, string>("display", "web/login") }; HttpContent content = new FormUrlEncodedContent(queryParameter); var query = await content.ReadAsStringAsync(); var uri = new Uri("https://accounts.ea.com/connect/auth?" + query, UriKind.Absolute); var response = await _httpClient.GetAsync(uri); var source = await response.Content.ReadAsStringAsync(); var parameters = response.RequestMessage.RequestUri.Query.Remove(0, 1).Split('&'); foreach (var parameter in parameters) { var parameterSplitted = parameter.Split('='); var key = parameterSplitted[0]; var value = WebUtility.UrlDecode(parameterSplitted[1]); if (key == "execution") { result.Execution = value; } else if (key == "initref") { result.Initref = value; } } // If HttpUtility is available in .Net 5 //var queryDuringRedirect = response.RequestMessage.RequestUri.ParseQueryString(); //result.Execution = queryDuringRedirect["execution"]; //result.Initref = queryDuringRedirect["initref"]; return result; }
private async Task<bool> Login(GetLoginPageResult getLoginPageResult, string email, string password) { var queryList = new[] { new KeyValuePair<string, string>("execution", getLoginPageResult.Execution), new KeyValuePair<string, string>("initref", getLoginPageResult.Initref) }; var bodyList = new[] { new KeyValuePair<string, string>("email", email), new KeyValuePair<string, string>("password", password), new KeyValuePair<string, string>("_rememberMe", "on"), new KeyValuePair<string, string>("rememberMe", "on"), new KeyValuePair<string, string>("_eventId", "submit"), new KeyValuePair<string, string>("gCaptchaResponse", "") }; HttpContent queryStringContent = new FormUrlEncodedContent(queryList); HttpContent bodyContent = new FormUrlEncodedContent(bodyList); var queryString = await queryStringContent.ReadAsStringAsync(); var uri = new Uri("https://signin.ea.com/p/web/login?" + queryString, UriKind.Absolute); var response = await _httpClient.PostAsync(uri, bodyContent); var source = await response.Content.ReadAsStringAsync(); if (response.RequestMessage.RequestUri == uri) { return false; } return true; }