Exemplo n.º 1
0
        public LoginResult GetRefreshToken(bool sisi, out string refreshToken)
        {
            string checkToken = sisi ? SisiRefreshToken : TranquilityRefreshToken;

            if (!string.IsNullOrEmpty(checkToken))
            {
                refreshToken = checkToken;
                return(LoginResult.Success);
            }

            // need PlaintextPassword.
            if (SecurePassword == null || SecurePassword.Length == 0)
            {
                Windows.EVELogin el     = new Windows.EVELogin(this, false);
                bool?            result = el.ShowDialog();

                if (SecurePassword == null || SecurePassword.Length == 0)
                {
                    // password is required, sorry dude
                    refreshToken = null;
                    return(LoginResult.InvalidUsernameOrPassword);
                }
            }

            string uri = "https://login.eveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dcode%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken%2520user";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dcode%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken%2520user";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 5000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                byte[] body1 = Encoding.ASCII.GetBytes(String.Format("UserName={0}&Password="******"Invalid username / password"))
                {
                    refreshToken = null;
                    return(LoginResult.InvalidUsernameOrPassword);
                }


                /*
                 * <span id="ValidationContainer"><div class="validation-summary-errors"><span>Login failed. Possible reasons can be:</span>
                 * <ul><li>Invalid username / password</li>
                 * </ul></div></span>
                 */

                //                https://login.eveonline.com/launcher?client_id=eveLauncherTQ#access_token=l4nGki1CTUI7pCQZoIdnARcCLqL6ZGJM1X1tPf1bGKSJxEwP8lk_shS19w3sjLzyCbecYAn05y-Vbs-Jm1d1cw2&token_type=Bearer&expires_in=43200
                //accessToken = new Token(resp.ResponseUri);
                refreshCode = HttpUtility.ParseQueryString(resp.ResponseUri.Query).Get("code");

                // String expires_in = HttpUtility.ParseQueryString(fromUri.Fragment).Get("expires_in");
            }

            GetTokensFromCode(sisi, refreshCode);
            throw new NotImplementedException();

            if (!sisi)
            {
                TranquilityRefreshToken = refreshToken;
            }
            else
            {
                SisiRefreshToken = refreshToken;
            }

            return(LoginResult.Success);
        }
Exemplo n.º 2
0
        private void buttonAddAccount_Click(object sender, RoutedEventArgs e)
        {
            EVEAccount newAccount = new EVEAccount();
            EVELogin   el         = new EVELogin(newAccount, false);

            el.ShowDialog();

            if (el.DialogResult.HasValue && el.DialogResult.Value)
            {
                // user clicked Go

                // check password...
                //                string refreshToken;
                //                switch (newAccount.GetRefreshToken(false, out refreshToken))
                EVEAccount.Token token;
                LoginResult      lr = newAccount.GetAccessToken(false, out token);
                switch (lr)
                {
                case LoginResult.Success:
                    break;

                case LoginResult.InvalidUsernameOrPassword:
                {
                    MessageBox.Show("Invalid Username or Password. Account NOT added.");
                    return;
                }

                case LoginResult.Timeout:
                {
                    MessageBox.Show("Timed out attempting to log in. Account NOT added.");
                    return;
                }

                case LoginResult.InvalidCharacterChallenge:
                {
                    MessageBox.Show("Invalid Character Name entered, or Invalid Username or Password. Account NOT added.");
                    return;
                }

                case LoginResult.EmailVerificationRequired:
                    // message already provided
                    return;

                default:
                {
                    MessageBox.Show("Failed to log in: " + lr.ToString() + ". Account NOT added.");
                    return;
                }
                break;
                }



                EVEAccount existingAccount = App.Settings.Accounts.FirstOrDefault(q => q.Username.Equals(newAccount.Username, StringComparison.InvariantCultureIgnoreCase));

                if (existingAccount != null)
                {
                    // update existing account?
                    existingAccount.Username       = newAccount.Username;
                    existingAccount.SecurePassword = newAccount.SecurePassword.Copy();
                    existingAccount.EncryptPassword();

                    if (newAccount.SecureCharacterName != null && newAccount.SecureCharacterName.Length > 0)
                    {
                        existingAccount.SecureCharacterName = newAccount.SecureCharacterName.Copy();
                        existingAccount.EncryptCharacterName();
                    }

                    newAccount.Dispose();
                    newAccount = existingAccount;
                }
                else
                {
                    // new account
                    App.Settings.Accounts.Add(newAccount);
                }

                App.Settings.Store();
            }
        }
Exemplo n.º 3
0
        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?            result = el.ShowDialog();

                    if (SecurePassword == null || SecurePassword.Length == 0)
                    {
                        // password is required, sorry dude
                        accessToken = null;
                        return(LoginResult.InvalidUsernameOrPassword);
                    }

                    App.Settings.Store();
                }
            }

            string uri = "https://login.eveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 30000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                byte[] body1 = Encoding.ASCII.GetBytes(String.Format("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.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));
        }