public void Logout() { Name = ""; Email = ""; Profile = null; _googleService.Logout(); }
async Task LoginGoogleAsync(AuthNetwork authNetwork) { try { if (!string.IsNullOrEmpty(_googleService.AccessToken)) { //Always require user authentication _googleService.Logout(); } EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null; userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) => { switch (e.Status) { case GoogleActionStatus.Completed: #if DEBUG var googleUserString = JsonConvert.SerializeObject(e.Data); Debug.WriteLine($"Google Logged in succesfully: {googleUserString}"); #endif var socialLoginData = new NetworkAuthData { Logo = authNetwork.Icon, Foreground = authNetwork.Foreground, Background = authNetwork.Background, Name = e.Data.Name, }; //await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData)); break; case GoogleActionStatus.Canceled: await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok"); break; case GoogleActionStatus.Error: await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok"); break; case GoogleActionStatus.Unauthorized: await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok"); break; } //_googleService.OnLogin -= userLoginDelegate; }; //_googleService.OnLogin += userLoginDelegate; await _googleService.LoginAsync(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public override void ViewDidLoad() { base.ViewDidLoad(); BtnLogout.Hidden = true; BtnLogout.TouchUpInside += (object sender, EventArgs e) => { _googleClientManager.Logout(); BtnLogin.Hidden = false; BtnLogout.Hidden = true; _googleClientManager.OnLogout += (object s, EventArgs ee) => { LblUsername.Text = string.Empty; LblEmailAddress.Text = string.Empty; FullImageView.Image = new UIImage(); }; }; BtnLogin.TouchUpInside += async delegate { _googleClientManager.OnLogin += _googleClientManager_OnLogin; try { await _googleClientManager.LoginAsync(); } catch (GoogleClientSignInNetworkErrorException e) { Console.WriteLine(e.Message); } catch (GoogleClientSignInCanceledErrorException e) { Console.WriteLine(e.Message); } catch (GoogleClientSignInInvalidAccountErrorException e) { Console.WriteLine(e.Message); } catch (GoogleClientSignInInternalErrorException e) { Console.WriteLine(e.Message); } catch (GoogleClientBaseException e) { Console.WriteLine(e.Message); } }; }
async Task LoginGoogleAsync() { try { if (!string.IsNullOrEmpty(_googleService.ActiveToken)) { //Always require user authentication _googleService.Logout(); } EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null; userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) => { switch (e.Status) { case GoogleActionStatus.Completed: await App.Current.MainPage.Navigation.PushModalAsync(new WelcomePage(e.Data)); break; case GoogleActionStatus.Canceled: await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok"); break; case GoogleActionStatus.Error: await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok"); break; case GoogleActionStatus.Unauthorized: await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok"); break; } _googleService.OnLogin -= userLoginDelegate; }; _googleService.OnLogin += userLoginDelegate; await _googleService.LoginAsync(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public void GoogleLogout() { _googleClientManager.OnLogout += OnGoogleLogoutCompleted; _googleClientManager.Logout(); }
public async void LogoutCommand(object sender, EventArgs e) { _googleClientManager.Logout(); Settings.User = ""; }
async Task LoginGoogleAsync() { try { if (!string.IsNullOrEmpty(_googleService.AccessToken)) { //Always require user authentication _googleService.Logout(); } EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null; userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) => { switch (e.Status) { case GoogleActionStatus.Completed: #if DEBUG var googleUserString = JsonConvert.SerializeObject(e.Data); Debug.WriteLine($"Google Logged in succesfully: {googleUserString}"); #endif var socialLoginData = new EquipmentsViewModel.Nav { Data = new NetworkAuthData { Id = e.Data.Id, Picture = e.Data.Picture.AbsoluteUri, Name = e.Data.Name, } }; //await this.CoreMethods.PushPageModel<EquipmentsViewModel>(socialLoginData, true); var page = FreshPageModelResolver.ResolvePageModel <EquipmentsViewModel>(socialLoginData); var basicNavContainer = new FreshNavigationContainer(page); Application.Current.MainPage = basicNavContainer; break; case GoogleActionStatus.Canceled: await this.CoreMethods.DisplayAlert("Google Auth", "Canceled", "Ok"); break; case GoogleActionStatus.Error: await this.CoreMethods.DisplayAlert("Google Auth", "Error", "Ok"); break; case GoogleActionStatus.Unauthorized: await this.CoreMethods.DisplayAlert("Google Auth", "Unauthorized", "Ok"); break; } _googleService.OnLogin -= userLoginDelegate; }; _googleService.OnLogin += userLoginDelegate; await _googleService.LoginAsync(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
private async Task LoginGoogleAsync() { try { //Check if the user is already logged in //potentially will remove this in the future otherwise create appropriate handler if (!string.IsNullOrEmpty((googleClient.AccessToken))) { googleClient.Logout(); } //Create the event/delegate of Google user type and initialize it EventHandler <GoogleClientResultEventArgs <GoogleUser> > userLoginDelegate = null; //Lets do the login userLoginDelegate = async(object sender, GoogleClientResultEventArgs <GoogleUser> e) => { switch (e.Status) { case GoogleActionStatus.Completed: var googleResultString = JsonConvert.SerializeObject(e.Data); //A check with the user profile image is empty string url = string.Empty; if (e.Data.Picture.AbsoluteUri != null) { url = e.Data.Picture.AbsoluteUri; } //map the e.data into our SocialMediaUser model var socialMediaUser = new SocialMediaUser { Email = e.Data.Email, Name = e.Data.Name, PictureURL = url }; //Once the model is set, send it to the selectLeague page await App.Current.MainPage.Navigation.PushModalAsync(new SelectLeagues()); break; case GoogleActionStatus.Canceled: /*For now we will display an alert here but we will move this elsewhere * so that we can just return a msg into that VM and display it properly * and finally navigate to login page */ await App.Current.MainPage.DisplayAlert("Google Login", "Google Login Cancelled by user", "OK"); await App.Current.MainPage.Navigation.PushModalAsync(new LoginPage()); break; case GoogleActionStatus.Error: /*For now we will display an alert here but we will move this elsewhere * so that we can just return a msg into that VM and display it properly * and finally navigate to login page */ await App.Current.MainPage.DisplayAlert("Google Login", "Error from Google signing in", "OK"); await App.Current.MainPage.Navigation.PushModalAsync(new LoginPage()); break; } googleClient.OnLogin -= userLoginDelegate; }; googleClient.OnLogin += userLoginDelegate; await googleClient.LoginAsync(); } catch (Exception e) { Debug.WriteLine(e.ToString()); //await App.Current.MainPage.DisplayAlert("Google Login", e.Message, "OK"); } }
public void Logout() { googleClientManager.OnLogout += OnLogoutCompleted; googleClientManager.Logout(); }