private async void Login_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(UsernameTextBox.Text)) { return; } if (string.IsNullOrWhiteSpace(PasswordTextBox.Password)) { return; } LoadingOverlay.Visibility = Visibility.Visible; SessionManager.MobileClient = new MobileClient(); if (await SessionManager.MobileClient.LoginAsync(UsernameTextBox.Text, PasswordTextBox.Password)) { Settings.Default.UserEmail = UsernameTextBox.Text; Settings.Default.UserMasterToken = StringCipher.Encrypt(PasswordTextBox.Password, GoogleAuth.GetPcMacAddress()); Settings.Default.Save(); FinishLogin(); } else { MessageBox.Show( "Incorrect Username or Password!\nPlease make sure 2 factor authentication is disabled, or you are using an application password.", "Login Failed!"); LoadingOverlay.Visibility = Visibility.Hidden; } }
/// <summary> /// Check if the specified Authorization Token is still valid, and if it is collect required information to login. /// </summary> /// <param name="email">The Email of the account</param> /// <param name="token">The Master Authorization Token, if left null will use the Authorization Token associated to this <see cref="MobileClient"/> (If specified in constructor)</param> /// <returns></returns> public async Task <bool> LoginWithToken(string email, string token = null) { Debug.WriteLine($"Attempting Login ({email})..."); try { Session = new MobileSession(new UserDetails(email, "", GoogleAuth.GetPcMacAddress())); return(await Session.LoginAsync(token)); } catch (HttpRequestException) { return(false); } }
/// <summary> /// Login to Google Play Music with the specified email and password. /// This will make two requests to the Google Authorization Server, and collect an Authorization Token to use for all requests. /// </summary> /// <param name="email">The Email / Username of the google account</param> /// <param name="password">The Password / App Specific password (https://security.google.com/settings/security/apppasswords)</param> public sealed override async Task <bool> LoginAsync(string email, string password) { try { Debug.WriteLine($"Attempting Login ({email})..."); Session = new MobileSession(new UserDetails(email, password, GoogleAuth.GetPcMacAddress())); return(await Session.LoginAsync()); } catch (HttpRequestException) { return(false); } }
private async void Login_Loaded(object sender, RoutedEventArgs e) { SessionManager.MobileClient = new MobileClient(); if (await SessionManager.MobileClient.LoginWithToken(Settings.Default.UserEmail, StringCipher.Decrypt(Settings.Default.UserMasterToken, GoogleAuth.GetPcMacAddress()))) { FinishLogin(); } else { LoadingOverlay.Visibility = Visibility.Hidden; } }