public async void OnAuthComplete(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated && e.Account != null && User != null) { MainPage = new MainPage(); await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName); } }
// TODO: Clean up async/void - Sweeky! ;-) async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { var request = e.Account; //var access_token = request.Properties["access_token"]; await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName); await Shell.Current.GoToAsync("//main"); } }
private async void SubmitButtonClicked(object obj) { AppController.AddBusy("SignInViewModel"); IsPasswordEmpty = string.IsNullOrEmpty(Password); if (string.IsNullOrEmpty(Mail) || !mail.Contains("@") || !mail.Contains(".")) { HasError = true; } else if (!isPasswordEmpty) { if (await DoLogin(Mail, Password, true)) { // Save this. Account account = new Account { Username = Mail }; account.Properties.Add("Password", Password); await SecureStorageAccountStore.SaveAsync(account, App.AppName); } } AppController.RemoveBusy("SignInViewModel"); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { if (authenticator.AuthorizeUrl.Host == "www.facebook.com") { FacebookEmail facebookEmail = null; var httpClient = new HttpClient(); var json = await httpClient.GetStringAsync($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"]); facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(json); //await store.SaveAsync(account = e.Account, Constants.AppName); try { await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName); } catch { } Application.Current.Properties.Remove("Id"); Application.Current.Properties.Remove("FirstName"); Application.Current.Properties.Remove("LastName"); Application.Current.Properties.Remove("DisplayName"); Application.Current.Properties.Remove("EmailAddress"); Application.Current.Properties.Remove("ProfilePicture"); Application.Current.Properties.Add("Id", facebookEmail.Id); Application.Current.Properties.Add("FirstName", facebookEmail.First_Name); Application.Current.Properties.Add("LastName", facebookEmail.Last_Name); Application.Current.Properties.Add("DisplayName", facebookEmail.Name); Application.Current.Properties.Add("EmailAddress", facebookEmail.Email); Application.Current.Properties.Add("ProfilePicture", facebookEmail.Picture.Data.Url); //await Navigation.PushAsync(new ProfilePage()); // await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true); await NavigationService.NavigateToAsync <BikeDetailViewModel>(); } else { SocialMediaUser user = null; // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var request = new OAuth2Request("GET", new Uri(Constants.GoogleUserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { // Deserialize the data and store it in the account store // The users email address will be used to identify data in SimpleDB string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <SocialMediaUser>(userJson); } /*if (account != null) * { * store.Delete(account, Constants.AppName); * } * await store.SaveAsync(account = e.Account, Constants.AppName); */ try { await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName); } catch { } Application.Current.Properties.Remove("Id"); Application.Current.Properties.Remove("FirstName"); Application.Current.Properties.Remove("LastName"); Application.Current.Properties.Remove("DisplayName"); Application.Current.Properties.Remove("EmailAddress"); Application.Current.Properties.Remove("ProfilePicture"); Application.Current.Properties.Add("Id", user.Id); Application.Current.Properties.Add("FirstName", user.GivenName); Application.Current.Properties.Add("LastName", user.FamilyName); Application.Current.Properties.Add("DisplayName", user.Name); Application.Current.Properties.Add("EmailAddress", user.Email); Application.Current.Properties.Add("ProfilePicture", user.Picture); //await Navigation.PushAsync(new ProfilePage()); await NavigationService.NavigateToAsync <BikeDetailViewModel>(); // await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true); } } }