Esempio n. 1
0
        public async Task Login(string windowsLiveAuthServer)
        {
            // get identity
            Write("Microsoft Account Email Address: ");
            var identity = ReadLine();

            // get password
            Write("Microsoft Account Password: "******"*");
                }
                else
                {
                    if (key.Key == ConsoleKey.Backspace && identityPassword.Length > 0)
                    {
                        identityPassword = identityPassword.Substring(0, (identityPassword.Length - 1));
                        Write("\b \b");
                    }
                }
            }while (key.Key != ConsoleKey.Enter);
            WriteLine();

            // get two fac
            Write("Microsoft Account Two Factor Code (Optional): ");
            var identityTwoFactorCode = ReadLine();

            Write("Authenticating with Windows Live... ");
            var windowsLiveAuthentication = await Authentication.AuthenticateWindowsLiveAsync(windowsLiveAuthServer, identity, identityPassword, identityTwoFactorCode);

            WriteLine("Done");

            Write("Authenticating with Xbox Live... ");
            var xboxLiveAuthentication = await Authentication.AuthenticateXboxLiveAsync(windowsLiveAuthentication.AccessToken);

            WriteLine("Done");

            Write("Authorizing with Xbox Live... ");
            var xboxLiveAuthorization = await Authentication.AuthorizeXboxLiveAsync(xboxLiveAuthentication.Token);

            WriteLine("Done");

            var settings = GetSettings();

            settings.AccessToken       = windowsLiveAuthentication.AccessToken;
            settings.RefreshToken      = windowsLiveAuthentication.RefreshToken;
            settings.ExpiresAt         = DateTime.UtcNow.AddSeconds(windowsLiveAuthentication.ExpiresIn - 40);
            settings.XboxUserId        = xboxLiveAuthorization.DisplayClaims.Xui[0].XboxUserId;
            settings.Token             = xboxLiveAuthorization.Token;
            settings.AgeGate           = xboxLiveAuthorization.DisplayClaims.Xui[0].AgeGate;
            settings.Gamertag          = xboxLiveAuthorization.DisplayClaims.Xui[0].Gamertag;
            settings.UserHeaderSession = xboxLiveAuthorization.DisplayClaims.Xui[0].UserHeaderSession;
            SetSettings(settings);

            WriteLine();
            WriteLine(" --- ");
            WriteLine();
            WriteLine("Signed in as {0} ({1}) - {2} account.", settings.Gamertag, settings.XboxUserId, settings.AgeGate);
        }