private LoginResult GetAccessToken(bool sisi, string authCode, out Response response) { HttpWebRequest req2 = RequestResponse.CreatePostRequest(new Uri(RequestResponse.token, UriKind.Relative), sisi, true, RequestResponse.refererUri, Cookies); req2.SetBody(RequestResponse.GetSsoTokenRequestBody(sisi, authCode, challengeCode)); return(RequestResponse.GetHttpWebResponse(req2, UpdateCookieStorage, out response)); }
public LoginResult GetAccessToken(bool sisi, out Token accessToken) { Token checkToken = sisi ? SisiToken : TranquilityToken; if (checkToken != null && !checkToken.IsExpired) { accessToken = checkToken; return(LoginResult.Success); } // need SecurePassword. if (SecurePassword == null || SecurePassword.Length == 0) { DecryptPassword(true); if (SecurePassword == null || SecurePassword.Length == 0) { Windows.EVELogin el = new Windows.EVELogin(this, true); bool? dialogResult = el.ShowDialog(); if (SecurePassword == null || SecurePassword.Length == 0) { // password is required, sorry dude accessToken = null; return(LoginResult.InvalidUsernameOrPassword); } App.Settings.Store(); } } var uri = RequestResponse.GetLoginUri(sisi, state.ToString(), challengeHash); string RequestVerificationToken = string.Empty; var result = GetRequestVerificationToken(uri, sisi, out RequestVerificationToken); var req = RequestResponse.CreatePostRequest(uri, sisi, true, "URL", Cookies); using (SecureBytesWrapper body = new SecureBytesWrapper()) { byte[] body1 = Encoding.ASCII.GetBytes(String.Format("__RequestVerificationToken={1}&UserName={0}&Password="******"UserName={0}&Password=", Uri.EscapeDataString(Username))); using (SecureStringWrapper ssw = new SecureStringWrapper(SecurePassword, Encoding.ASCII)) { using (SecureBytesWrapper escapedPassword = new SecureBytesWrapper()) { escapedPassword.Bytes = System.Web.HttpUtility.UrlEncodeToBytes(ssw.ToByteArray()); body.Bytes = new byte[body1.Length + escapedPassword.Bytes.Length]; System.Buffer.BlockCopy(body1, 0, body.Bytes, 0, body1.Length); System.Buffer.BlockCopy(escapedPassword.Bytes, 0, body.Bytes, body1.Length, escapedPassword.Bytes.Length); req.SetBody(body); } } } return(GetAccessToken(sisi, req, out accessToken)); }
public LoginResult GetAuthenticatorChallenge(bool sisi, out Token accessToken) { Windows.AuthenticatorChallengeWindow acw = new Windows.AuthenticatorChallengeWindow(this); acw.ShowDialog(); if (!acw.DialogResult.HasValue || !acw.DialogResult.Value) { SecurePassword = null; accessToken = null; return(LoginResult.InvalidAuthenticatorChallenge); } var uri = RequestResponse.GetAuthenticatorUri(sisi, state.ToString(), challengeHash); var req = RequestResponse.CreatePostRequest(uri, sisi, true, uri.ToString(), Cookies); using (SecureBytesWrapper body = new SecureBytesWrapper()) { body.Bytes = Encoding.ASCII.GetBytes(String.Format("Challenge={0}&RememberTwoFactor={1}&command={2}", Uri.EscapeDataString(acw.AuthenticatorCode), "true", "Continue")); req.ContentLength = body.Bytes.Length; try { using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(body.Bytes, 0, body.Bytes.Length); } } catch (System.Net.WebException e) { switch (e.Status) { case WebExceptionStatus.Timeout: { accessToken = null; return(LoginResult.Timeout); } default: throw; } } } LoginResult result = GetAccessToken(sisi, req, out accessToken); if (result == LoginResult.Success) { // successful authenticator challenge, make sure we save the cookies. App.Settings.Store(); } return(result); }
public LoginResult GetCharacterChallenge(bool sisi, out Token accessToken) { // need SecureCharacterName. if (SecureCharacterName == null || SecureCharacterName.Length == 0) { DecryptCharacterName(true); if (SecureCharacterName == null || SecureCharacterName.Length == 0) { Windows.CharacterChallengeWindow ccw = new Windows.CharacterChallengeWindow(this); bool?result = ccw.ShowDialog(); if (string.IsNullOrWhiteSpace(ccw.CharacterName)) { // CharacterName is required, sorry dude accessToken = null; // SecurePassword = null; SecureCharacterName = null; return(LoginResult.InvalidCharacterChallenge); } SecureCharacterName = new System.Security.SecureString(); foreach (char c in ccw.CharacterName) { SecureCharacterName.AppendChar(c); } SecureCharacterName.MakeReadOnly(); EncryptCharacterName(); App.Settings.Store(); } } var uri = RequestResponse.GetCharacterChallengeUri(sisi, state.ToString(), challengeHash); var req = RequestResponse.CreatePostRequest(uri, sisi, true, uri.ToString(), Cookies); using (SecureBytesWrapper body = new SecureBytesWrapper()) { byte[] body1 = Encoding.ASCII.GetBytes(String.Format("RememberCharacterChallenge={0}&Challenge=", "true")); using (SecureStringWrapper ssw = new SecureStringWrapper(SecureCharacterName, Encoding.ASCII)) { using (SecureBytesWrapper escapedCharacterName = new SecureBytesWrapper()) { escapedCharacterName.Bytes = System.Web.HttpUtility.UrlEncodeToBytes(ssw.ToByteArray()); body.Bytes = new byte[body1.Length + escapedCharacterName.Bytes.Length]; System.Buffer.BlockCopy(body1, 0, body.Bytes, 0, body1.Length); System.Buffer.BlockCopy(escapedCharacterName.Bytes, 0, body.Bytes, body1.Length, escapedCharacterName.Bytes.Length); } } req.ContentLength = body.Bytes.Length; try { using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(body.Bytes, 0, body.Bytes.Length); } } catch (System.Net.WebException e) { switch (e.Status) { case WebExceptionStatus.Timeout: { accessToken = null; return(LoginResult.Timeout); } default: throw; } } } return(GetAccessToken(sisi, req, out accessToken)); }
public LoginResult GetEULAChallenge(bool sisi, string responseBody, Uri referer, out Token accessToken) { Windows.EVEEULAWindow eulaWindow = new Windows.EVEEULAWindow(responseBody); eulaWindow.ShowDialog(); if (!eulaWindow.DialogResult.HasValue || !eulaWindow.DialogResult.Value) { SecurePassword = null; accessToken = null; return(LoginResult.EULADeclined); } //string uri = "https://login.eveonline.com/OAuth/Eula"; //if (sisi) //{ // uri = "https://sisilogin.testeveonline.com/OAuth/Eula"; //} var uri = RequestResponse.GetEulaUri(sisi, state.ToString(), challengeHash); HttpWebRequest req = RequestResponse.CreatePostRequest(uri, sisi, true, referer.ToString(), Cookies); using (SecureBytesWrapper body = new SecureBytesWrapper()) { string eulaHash = RequestResponse.GetEulaHashFromBody(responseBody); string returnUrl = RequestResponse.GetEulaReturnUrlFromBody(responseBody); string formattedString = String.Format("eulaHash={0}&returnUrl={1}&action={2}", Uri.EscapeDataString(eulaHash), Uri.EscapeDataString(returnUrl), "Accept"); body.Bytes = Encoding.ASCII.GetBytes(formattedString); req.ContentLength = body.Bytes.Length; try { using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(body.Bytes, 0, body.Bytes.Length); } } catch (System.Net.WebException e) { switch (e.Status) { case WebExceptionStatus.Timeout: { accessToken = null; return(LoginResult.Timeout); } default: throw; } } } LoginResult result; try { result = GetAccessToken(sisi, req, out accessToken); } catch (System.Net.WebException) { result = GetAccessToken(sisi, out accessToken); } result = GetAccessToken(sisi, req, out accessToken); if (result == LoginResult.Success) { // successful verification code challenge, make sure we save the cookies. App.Settings.Store(); } return(result); }