public static async void OnAuthCompleted(Object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } UserObj user = null; if (e.IsAuthenticated) { var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <UserObj>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); 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.FirstName); Application.Current.Properties.Add("LastName", user.LastName); Application.Current.Properties.Add("DisplayName", user.Name); Application.Current.Properties.Add("EmailAddress", user.Email); Application.Current.Properties.Add("ProfilePicture", user.Picture); Application.Current.MainPage.Navigation.PopAsync(); Application.Current.MainPage.Navigation.PushAsync(new TabbedPage1(), true); } }
public virtual async Task <Token> LoginWithCredentials(string username, string password, string client_id, string client_secret, string[] scopes = null, CancellationToken cancellationToken = default(CancellationToken)) { await Logout(state : null, client_id : client_id, cancellationToken : cancellationToken); if (scopes == null) { scopes = "openid profile user_info".Split(' '); } TokenClient tokenClient = _containerProvider.GetContainer().Resolve <TokenClient>(new NamedParameter("clientId", client_id), new NamedParameter("secret", client_secret)); TokenResponse tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(username, password, scope : string.Join(" ", scopes), cancellationToken : cancellationToken).ConfigureAwait(false); if (tokenResponse.IsError) { throw tokenResponse.Exception ?? new Exception($"{tokenResponse.Error} {tokenResponse.Raw}"); } Account account = Token.FromTokenToAccount(tokenResponse); await _accountStore.SaveAsync(account, _clientAppProfile.AppName).ConfigureAwait(false); return(account); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { //UserInfo = https://www.googleapis,com/oaurh2/v2/userinfo var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); await DisplayAlert("Name", User.Name, "OK"); await DisplayAlert("Email Address", User.Email, "OK"); try { UsersDb.AddUser(user); } catch (SqlException ex) { } App.CurrentUser = user; } Application.Current.MainPage = new HomePage(); await Shell.Current.GoToAsync("//main"); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); //UserDialogs.Instance.Alert("", "Email address: " + user.Email + "\n fullname:" + user.Name + "\n gender:" + user.Gender, "OK"); MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.Green, "Successful google login")); User.Username = user.Email; User.Password = user.Email; } else { MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.PaleVioletRed, "Unsuccessful google login")); } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } Application.Current.Properties["User"] = user; await store.SaveAsync(account = e.Account, Constants.AppName); Application.Current.Properties["Account"] = (await store.FindAccountsForServiceAsync(Constants.AppName)).FirstOrDefault(); Application.Current.Properties["Signed"] = true; Xamarin.Forms.Application.Current.Properties["Boff"] = "Hello " + user.Name + "\n" + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Welcome2"); loader.Tokenise(); } else { Xamarin.Forms.Application.Current.Properties["Boff"] = "error"; } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); // await DisplayAlert("Email address", user.Email, "OK"); // Disable back button on search page var mainPage = new MainPage(); NavigationPage.SetHasBackButton(mainPage, false); await Navigation.PushAsync(mainPage); } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } try { await store.SaveAsync(account = e.Account, Constants.AppName); } catch { await DisplayAlert("Email address", "keychain", "OK"); } Xamarin.Forms.Application.Current.Properties["Boff"] = "Hello " + user.Name + "! \nWelcome to GreenBank"; Xamarin.Forms.Application.Current.Properties["First"] = user.GivenName; Xamarin.Forms.Application.Current.Properties["Last"] = user.FamilyName; Xamarin.Forms.Application.Current.Properties["Signed"] = true; Application.Current.Properties["Account"] = e.Account; } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } UserProfile userProfile = null; if (e.IsAuthenticated) { var tokeType = e.Account.Properties.ContainsKey("token_type") ? e.Account.Properties["token_type"] : ""; var accessToken = e.Account.Properties.ContainsKey("access_token") ? e.Account.Properties["access_token"] : ""; var expires = e.Account.Properties.ContainsKey("expires_in") ? e.Account.Properties["expires_in"] : ""; Debug.WriteLine($"{tokeType} Access Token : {accessToken}"); var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { var result = await response.GetResponseTextAsync(); userProfile = JsonConvert.DeserializeObject <UserProfile>(result, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); Debug.WriteLine(result); } if (_account != null) { await _store.DeleteAsync(_account, Constants.AppName); await _store.SaveAsync(_account = e.Account, Constants.AppName); } } }
public async Task <bool> LoginAsync() { var user = await _authenticator.Authenticate(Provider); if (user == null) { return(false); } _mobileService.CurrentUser = user; var account = new Account(user.UserId); account.Properties["Password"] = user.MobileServiceAuthenticationToken; await _accountStore.SaveAsync(account, AuthProvider); await _dataService.GetProfileAsync(); return(true); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); Debug.WriteLine(user.Picture); Navigation.InsertPageBefore(new MainPage(), this); await Navigation.PopAsync(); } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } UserInfo user = null; if (e.IsAuthenticated) { //if the authentication is successful. // Sending a request to identity provider (Google) for retrieving the basic user data // UserInfoUrl has been defined in the "AppAuthenParameters" class var request = new OAuth2Request("GET", new Uri(AppAuthenParameters.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { // Deserialize the data and store it in the account store string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <UserInfo>(userJson); } //Due to we use the FindAccountsForService class, we will delete the saved account if (account != null) { store.Delete(account, AppAuthenParameters.AppName); } //Using Async method to save the new account await store.SaveAsync(account = e.Account, AppAuthenParameters.AppName); //Presents an alert dialog to the application user with a single cancel button await DisplayAlert("Email address", user.Email, "OK"); } }
public async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (sender is OAuth2Authenticator authenticator) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { User user = await GetGoogleUserInfo(e.Account); if (account != null) { store.Delete(account, Constants.AppName); } e.Account.Username = user.Name; await store.SaveAsync(account = e.Account, Constants.AppName); App.IrParaAplicacao(); //await DisplayAlert("Sucesso", "Usuário: " + user.Name, "OK"); } }
public async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (sender is OAuth2Authenticator authenticator) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { User user = null; switch (loginFrom) { case Constants.FROM_GOOGLE: user = await GetGoogleUserInfo(e.Account); break; case Constants.FROM_FACEBOOK: user = await GetFacebookUserInfo(e.Account); break; } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); // salva dados do usuário na base de dados local App.usrCorrente = await UsuariosBD.InsereAtualizaUsuario(user, loginFrom); // mostra página inicial await App.MostrarPaginaInicial(); } }
public async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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("https://www.googleapis.com/oauth2/v2/userinfo"), 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 <User>(userJson); } if (account != null) { store.Delete(account, serviceId: "655782672996-f7n91tloeocgksh8dogfuijhpfcre2m1.apps.googleusercontent.com"); } await store.SaveAsync(account = e.Account, serviceId : "655782672996-f7n91tloeocgksh8dogfuijhpfcre2m1.apps.googleusercontent.com"); await DisplayAlert("Email address", "Google", cancel : "OK"); } }
public async Task <Models.Account> LoginAccount(AccountLogin login) { var accountToken = await _accountTokenRepository.LoginAccount(login); Debug.WriteLine("Get token from accountservice: " + accountToken.Token); // Set our logged in token App.ServiceManager.setAuthenticationToken(accountToken.Token); // Correctly set our token so we are authenticated var account = await _accountRepository.GetAccount(); // If we found the old account, remove it with the new logged in one if (XamarinAccount != null) { AccountStore.Delete(XamarinAccount, Constants.AppName); } // Save the account token so we can login again later var xamarinAccount = new Xamarin.Auth.Account(account.Email); xamarinAccount.Properties.Add("Token", accountToken.Token); await AccountStore.SaveAsync(xamarinAccount, Constants.AppName); return(account); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } GoogleUsers user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <GoogleUsers>(userJson); user.IsToggled = false; user.IsLoggedIn = true; } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); bool newuser = false; if (await FirebaseHelper.CheckEmail(user.Email) == false) { await FirebaseHelper.AddUser(user.Email, user.Picture, user.Name, user.Id, user.IsToggled, user.IsLoggedIn); newuser = true; } ClearPersisitance(); 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); Application.Current.Properties.Add("IsToggled", false); await Application.Current.SavePropertiesAsync(); //persistance if (newuser) { await FirebaseHelper.AddPantryItem("Example Item", "5", "12/15"); } App.Current.MainPage = new AppShell(); } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } TurnOnLoginSpinner(true); User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); App app = App.Current; // Reject non UCSC domains string[] domainCheck = user.Email.Split('@'); if (!String.Equals(domainCheck[1], "ucsc.edu", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("[OAuth_OnAuthCompleted] Authentication error: Not a UCSC email"); app.ShowLogin(); await DisplayAlert("Authentication Error", "Not a UCSC email", "OK"); LoginUtils.SetUserLoggedOut(); await Application.Current.SavePropertiesAsync(); } else { if (await app.UserProfileManager.Init(user.Email)) { app.ShowMain(); } else { app.UserInfo.NameFirst = user.Name; app.UserInfo.NameLast = user.FamilyName; app.ShowProfileCreation(); } LoginUtils.SetUserLoggedIn(); } TurnOnLoginSpinner(false); } }
private async void AccountStoreTestsAsync(object authenticator, AuthenticatorCompletedEventArgs ee) { AccountStore account_store = AccountStore.Create(); await account_store.SaveAsync(ee.Account, provider); //------------------------------------------------------------------ // Android // https://kb.xamarin.com/agent/case/225411 // cannot reproduce try { //------------------------------------------------------------------ // Xamarin.iOS - following line throws IEnumerable <Account> accounts = await account_store.FindAccountsForServiceAsync(provider); Account account1 = accounts.FirstOrDefault(); //------------------------------------------------------------------ if (null != account1) { string token = default(string); string token_name = default(string); Type t = authenticator.GetType(); if (t == typeof(Xamarin.Auth.OAuth2Authenticator)) { token_name = "access_token"; token = account1.Properties[token_name].ToString(); } else if (t == typeof(Xamarin.Auth.OAuth1Authenticator)) { token_name = "oauth_token"; token = account1.Properties[token_name].ToString(); } UIAlertView alert = new UIAlertView ( "Token 3", "access_token = " + token, null, "OK", null ); alert.Show(); } } catch (System.Exception exc) { // Xamarin.iOS // exc {System.ArgumentNullException: Value cannot be null. // Parameter name: data // at Foundation.NSString.Fr…} System.ArgumentNullException // Value cannot be null. // Parameter name: data string msg = exc.Message; System.Diagnostics.Debug.WriteLine("Exception AccountStore: " + msg); } try { await AccountStore.Create().SaveAsync(ee.Account, provider + ".v.2"); } catch (System.Exception exc) { string msg = exc.Message; System.Diagnostics.Debug.WriteLine("Exception AccountStore: " + msg); } try { //------------------------------------------------------------------ // Xamarin.iOS - throws IEnumerable <Account> accounts = await account_store.FindAccountsForServiceAsync(provider + ".v.2"); Account account2 = accounts.FirstOrDefault(); //------------------------------------------------------------------ if (null != account2) { string token = default(string); string token_name = default(string); Type t = authenticator.GetType(); if (t == typeof(Xamarin.Auth.OAuth2Authenticator)) { token_name = "access_token"; token = account2.Properties[token_name].ToString(); } else if (t == typeof(Xamarin.Auth.OAuth1Authenticator)) { token_name = "oauth_token"; token = account2.Properties[token_name].ToString(); } UIAlertView alert = new UIAlertView ( "Token 4", "access_token = " + token, null, "OK", null ); alert.Show(); } } catch (System.Exception exc) { string msg = exc.Message; System.Diagnostics.Debug.WriteLine("Exception AccountStore: " + msg); } return; }
private async void AccountStoreTestsAsync(object authenticator, AuthenticatorCompletedEventArgs ee) { AccountStore account_store = AccountStore.Create(this); await account_store.SaveAsync(ee.Account, provider); //------------------------------------------------------------------ // Android // https://kb.xamarin.com/agent/case/225411 // cannot reproduce Account account1 = (await account_store.FindAccountsForServiceAsync(provider)).FirstOrDefault(); if (null != account1) { //------------------------------------------------------------------ string token = default(string); if (null != account1) { string token_name = default(string); Type t = authenticator.GetType(); if (t == typeof(Xamarin.Auth.OAuth2Authenticator)) { token_name = "access_token"; token = account1.Properties[token_name].ToString(); } else if (t == typeof(Xamarin.Auth.OAuth1Authenticator)) { token_name = "oauth_token"; token = account1.Properties[token_name].ToString(); } } //------------------------------------------------------------------ Toast.MakeText ( this, "access_token = " + token, ToastLength.Long ).Show(); } //------------------------------------------------------------------ AccountStore.Create(this).Save(ee.Account, provider + ".v.2"); //------------------------------------------------------------------ // throws on iOS // IEnumerable <Account> accounts = await(AccountStore.Create(this).FindAccountsForServiceAsync(provider + ".v.2")); Account account2 = accounts.FirstOrDefault(); if (null != account2) { //------------------------------------------------------------------ string token = default(string); if (null != account2) { string token_name = default(string); Type t = authenticator.GetType(); if (t == typeof(Xamarin.Auth.OAuth2Authenticator)) { token_name = "access_token"; token = account2.Properties[token_name].ToString(); } else if (t == typeof(Xamarin.Auth.OAuth1Authenticator)) { token_name = "oauth_token"; token = account2.Properties[token_name].ToString(); } } //------------------------------------------------------------------ Toast.MakeText ( this, "access_token = " + token, ToastLength.Long ).Show(); } //------------------------------------------------------------------ return; }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { try { using (UserDialogs.Instance.Loading("")) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { OAuth2Request oAuth2Request = null; string returnedJson = null; // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo switch (SocialMedia) { case "facebook": oAuth2Request = new OAuth2Request("GET", new Uri(Constants.graphAPI), null, e.Account); break; case "google": oAuth2Request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); break; default: break; } //var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await oAuth2Request.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(); switch (SocialMedia) { case "google": try { user = JsonConvert.DeserializeObject <User>(userJson); lvm.User.Username = user.Email; lvm.User.Password = user.Email; lvm.User.EmailAddress = user.Email; lvm.User.ConfirmPin = user.Email; } catch (Exception ex) { var log = ex; } break; case "facebook": try { var fbuser = JsonConvert.DeserializeObject <FaceBookProfile>(userJson); //var fbuser = JsonValue.Parse(response.GetResponseText()); lvm.User.Username = fbuser.Email; lvm.User.Password = fbuser.Email; lvm.User.EmailAddress = fbuser.Email; lvm.User.ConfirmPin = fbuser.Email; } catch (Exception ex) { var log = ex; } break; default: break; } } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); //UserDialogs.Instance.Alert("", "Email address: " + user.Email + "\n fullname:" + user.Name + "\n gender:" + user.Gender, "OK"); MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.Green, "Successful login")); GlobalStaticFields.Username = lvm.User.Username; var tk = await lvm.GetTokenFromAPI().ConfigureAwait(false); if (tk) { lvm.PersistUserDetails(); //Application.Current.MainPage.Navigation.PushAsync(new AppLanding()); Device.BeginInvokeOnMainThread ( async() => await Application.Current.MainPage.Navigation.PushAsync(new AppLanding()) ); } else { var reg = await lvm.Register().ConfigureAwait(false); if (reg) { //lvm.PersistUserDetails(); Application.Current.MainPage.Navigation.PushAsync(new AppLanding()); //Device.BeginInvokeOnMainThread // ( //async () => await Application.Current.MainPage.Navigation.PushAsync(new AppLanding()) //); } else { Device.BeginInvokeOnMainThread (() => UserDialogs.Instance.Toast(t.ShowMyToast(Color.OrangeRed, $"Unsuccessful. {lvm.RegisterationError} "))); } } } else { MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.PaleVioletRed, $"Unsuccessful {SocialMedia} login")); } } } catch (Exception ex) { var log = ex; } }
private 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); 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 FilesPage()); } else { GoogleFiles googleFiles = null; //GoogleAuthorizationCodeFlow.Initializer initializer = new GoogleAuthorizationCodeFlow.Initializer(); DriveService driveService = new DriveService(); //List<File> files = RetrieveAllFiles(driveService); //Console.WriteLine(files.Count); //// 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.GooglDriveFilesUrl), 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 data = await response.GetResponseTextAsync(); googleFiles = JsonConvert.DeserializeObject <GoogleFiles>(data); } //if (account != null) //{ // store.Delete(account, Constants.AppName); //} //await store.SaveAsync(account = e.Account, Constants.AppName); //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); var filePage = new FilesPage(); filePage.BindingContext = googleFiles.Items; await Navigation.PushAsync(filePage); } } }
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); 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 MainPage()); } else { NUsers 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 <NUsers>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); 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 MainPage()); } } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { using (UserDialogs.Instance.Loading("Iniciando Sesión")) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { String urlInfo = accountLoggedIn.Equals("Google") ? Constants.UserInfoUrl : "https://graph.facebook.com/me?fields=email"; // 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(urlInfo), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { FacebookResponse userFb = new FacebookResponse(); // 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<User>(userJson); if (accountLoggedIn.Equals("Google")) { user = JsonConvert.DeserializeObject <User>(userJson); } else { respuestaPerfil = await GetFacebookProfileAsync(); //userFb = JsonConvert.DeserializeObject<FacebookResponse>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); if (accountLoggedIn.Equals("Google")) { RegistrarPersona(user.Email, user.Name); } else { String correo = respuestaPerfil.Email; correo = correo.Replace(@"\\u0040", "@"); //await DisplayAlert("else de fb", correo, "ok"); RegistrarPersona(correo, respuestaPerfil.Name); } //await DisplayAlert("Email address", user.Email+", "+user.Name, "OK"); } } } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { using (UserDialogs.Instance.Loading("")) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { // 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.UserInfoUrl), 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 <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); //UserDialogs.Instance.Alert("", "Email address: " + user.Email + "\n fullname:" + user.Name + "\n gender:" + user.Gender, "OK"); MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.Green, "Successful google login")); lvm.User.Username = user.Email; lvm.User.Password = user.Email; lvm.User.EmailAddress = user.Email; lvm.User.ConfirmPin = user.Email; var tk = await lvm.GetTokenFromAPI().ConfigureAwait(false); if (tk) { Navigation.PushAsync(new AppLanding()); } else { var reg = await lvm.Register().ConfigureAwait(false); if (reg) { Device.BeginInvokeOnMainThread ( async() => Navigation.PushAsync(new AppLanding()) ); } else { Device.BeginInvokeOnMainThread (() => UserDialogs.Instance.Toast(t.ShowMyToast(Color.OrangeRed, $"Unsuccessful. {lvm.RegisterationError} "))); } } } else { MyToast t = new MyToast(); UserDialogs.Instance.Toast(t.ShowMyToast(Color.PaleVioletRed, "Unsuccessful google login")); } } }