コード例 #1
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            // SFSafariViewController doesn't dismiss itself
            DismissViewController(true, null);

            DisplayLoadingIndicator();

            var googleUserInfo = await _authViewModel.RetrieveGoogleUserInfoAsync(token.TokenType, token.AccessToken);

            var firebaseUserInfo = await _authViewModel.AuthenticateUserWithFirebaseAsync(googleUserInfo);

            if (firebaseUserInfo != null)
            {
                AuthCredential credential = GoogleAuthProvider.GetCredential(token.IdToken, token.AccessToken);
                AuthDataResult result     = await FirebaseManager.Auth.SignInAndRetrieveDataWithCredentialAsync(credential);

                token.SaveToDevice();
                googleUserInfo.SaveToDevice();
                firebaseUserInfo.SaveToDevice();

                PerformSegueToHome(googleUserInfo.GivenName);
            }
            else
            {
                await _authViewModel.RevokeTokenAsync(token.TokenType, token.AccessToken);

                RemoveLoadingIndicator();

                txtNotAuthorizedMessage.Text = _authViewModel.FirebaseNotAuthorizedErrorMessage;
                GoogleLoginButton.Hidden     = true;
            }
        }
コード例 #2
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            // Retrieve the user's email address
            var googleService = new GoogleService();
            var email         = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);

            ViewModel.ShowHomeViewModelCommand.Execute(null);
            ViewModel.AddUserToTable(email);
        }
コード例 #3
0
        public async void ProcessAuthenticationCompleted(GoogleOAuthToken token)
        {
            DismissViewController(true, null);

            var googleService = new GoogleService();

            _googleUser = await googleService.GetUserProfileAsync(token.TokenType, token.AccessToken);

            await ViewModel.SaveUserGoogleiOS(_googleUser);
        }
コード例 #4
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            // SFSafariViewController doesn't dismiss itself
            DismissViewController(true, null);

            var googleService = new GoogleService();
            var email         = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);

            GoogleLoginButton.SetTitle($"Connected with {email}", UIControlState.Normal);
        }
コード例 #5
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            DismissViewController(true, null);

            var googleService = new GoogleService();
            var email         = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);

            ViewModel.AddUserToTable(email);
            ViewModel.ShowHomeViewModelCommand.Execute(null);
        }
コード例 #6
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            try
            {
                var authenticator = sender as OAuth2Authenticator;
                if (authenticator != null)
                {
                    authenticator.Completed -= OnAuthCompleted;
                    authenticator.Error     -= OnAuthError;
                }

                User user = null;
                if (e.IsAuthenticated)
                {
                    // DismissViewController(true, null);


                    // If the user is authenticated, request their basic user data from Google
                    var request  = new OAuth2Request("GET", new Uri(MobileConstants.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 (user != null)
                        {
                            await Navigation.PushAsync(new Page1(user?.Email));
                        }
                    }

                    if (account != null)
                    {
                        store.Delete(account, MobileConstants.AppName);
                    }

                    await store.SaveAsync(account = e.Account, MobileConstants.AppName);

                    // await DisplayAlert("Email address", user.Email, "OK");

                    var token = new GoogleOAuthToken
                    {
                        TokenType   = e.Account.Properties["token_type"],
                        AccessToken = e.Account.Properties["access_token"]
                    };
                    // authenticator.IsLoadableRedirectUri()
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #7
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            // Retrieve the user's email address
            var googleService = new GoogleService();
            var email         = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);

            // Display it on the UI
            var googleButton = FindViewById <Android.Widget.Button>(Resource.Id.googleLoginButton);

            googleButton.Text = $"Connected with {email}";
        }
コード例 #8
0
 private void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e)
 {
     if (e.IsAuthenticated)
     {
         var token = new GoogleOAuthToken
         {
             TokenType   = e.Account.Properties["token_type"],
             AccessToken = e.Account.Properties["access_token"]
         };
         _authenticationDelegate.OnAuthenticationCompleted(token);
     }
     else
     {
         _authenticationDelegate.OnAuthenticationCanceled();
     }
 }
コード例 #9
0
        private void OnGoogleLoginButtonClicked(object sender, EventArgs e)
        {
            var googleToken = GoogleOAuthToken.ReadFromDevice().Result;
            var userInfo    = GoogleUserInfo.ReadFromDevice().Result;

            if (googleToken == null || userInfo == null)
            {
                var authenticator  = Auth.GetAuthenticator();
                var viewController = authenticator.GetUI();
                PresentViewController(viewController, true, null);
            }
            else
            {
                PerformSegueToHome(userInfo.GivenName);
            }
        }
コード例 #10
0
        private void ProcessAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs eventArgs)
        {
            if (!eventArgs.IsAuthenticated)
            {
                _authenticationDelegate.ProcessAuthenticationCanceled();
                return;
            }

            var token = new GoogleOAuthToken
            {
                TokenType   = eventArgs.Account.Properties[Constants.TokenType],
                AccessToken = eventArgs.Account.Properties[Constants.AccessToken]
            };

            _authenticationDelegate.ProcessAuthenticationCompleted(token);
        }
コード例 #11
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);
            // Retrieve the user's email address
            var googleService = new GoogleService();
            var email         = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);

            // Display it on the UI
            var googleButton = FindViewById <Button>(Resource.Id.googleLoginButton);

            googleButton.Text = $"Connected with {email}";
            var emailstr = googleButton.Text;


            //SetContentView(Resource.Layout.DashboardView);
        }
コード例 #12
0
        private void LogOut()
        {
            FirebaseManager.Auth.SignOut(out NSError error);

            if (error == null)
            {
                GoogleUserInfo.RemoveFromDevice();
                GoogleOAuthToken.RemoveFromDevice();
                FirebaseUserInfo.RemoveFromDevice();

                var rootNavController = Storyboard.InstantiateViewController("navLoginController") as UINavigationController;

                var appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
                appDelegate.Window.RootViewController = rootNavController;
            }
            else
            {
                DisplayErrorMessage("An error occurred while logging you out.");
            }
        }
コード例 #13
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            var googleService = new GoogleAccountInfoService();

            lbAccountInfo.Text = await googleService.GetEmailAsync(token.TokenType, token.AccessToken);
        }
コード例 #14
0
 public void OnAuthenticationCompleted(GoogleOAuthToken token)
 {
     Debug.WriteLine("ACCESS TOKEN : " + token.AccessToken);
     MessagingCenter.Send(this, "AuthSuccess", token.AccessToken);
 }