From b3ab8f8f175062df0876a42be552c6ec2a137640 Mon Sep 17 00:00:00 2001 From: Charles Macanka Date: Fri, 22 Oct 2021 13:05:00 -0400 Subject: [PATCH] Do not go to log in page for "login" process. If we already have the POESESSID, then we do not need to try to navigate to the login page. Instead, just see if we can navigate to the account page. If not, the authentication was not valid. This avoids needing to deal with CloudFlare at all. --- POEApi.Transport/HttpTransport.cs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/POEApi.Transport/HttpTransport.cs b/POEApi.Transport/HttpTransport.cs index 92c9c59c..b2370e49 100644 --- a/POEApi.Transport/HttpTransport.cs +++ b/POEApi.Transport/HttpTransport.cs @@ -26,6 +26,7 @@ protected enum HttpMethod { GET, POST } private string _proxyDomain; private const string LoginURL = @"https://www.pathofexile.com/login"; + private const string AccountURL = @"https://www.pathofexile.com/my-account"; private const string AccountNameURL = @"https://www.pathofexile.com/character-window/get-account-name?realm={0}"; private const string CharacterURL = @"https://www.pathofexile.com/character-window/get-characters?&realm={0}"; private const string StashURL = @"https://www.pathofexile.com/character-window/get-stash-items?league={0}&tabs=1&tabIndex={1}&accountName={2}&realm={3}"; @@ -80,21 +81,8 @@ public bool Authenticate(string email, SecureString password) credentialCookies.Add(new Cookie("POESESSID", unwrappedPassword, "/", ".pathofexile.com")); - try - { - TraditionalSessionIdLogin(); - return true; - } - catch (WebException ex) - { - if (((HttpWebResponse)ex.Response).Server == "cloudflare" && ((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.ServiceUnavailable) - { - CloudFlareSessionIdLogin(); - return true; - } - - throw; - } + TraditionalSessionIdLogin(); + return true; } private void CloudFlareSessionIdLogin() @@ -126,11 +114,12 @@ private void CloudFlareSessionIdLogin() private void TraditionalSessionIdLogin() { - using (var sessionIdLoginResponse = BuildHttpRequestAndGetResponse(HttpMethod.GET, LoginURL)) + using (var sessionIdLoginResponse = BuildHttpRequestAndGetResponse(HttpMethod.GET, AccountURL)) { - // If the response URI is the login URL, then the login action failed. - if (sessionIdLoginResponse.ResponseUri.ToString() == LoginURL) + if (sessionIdLoginResponse.ResponseUri.ToString() != AccountURL) + { throw new LogonFailedException(); + } } }