public MainViewController()
            : base(UITableViewStyle.Grouped, null)
        {
            SignIn.SharedInstance.Delegate = this;
            SignIn.SharedInstance.UIDelegate = this;

            // Automatically sign in the user.
            SignIn.SharedInstance.SignInUserSilently ();

            status = new StringElement ("Not Signed In", () => {
                // Sign out
                SignIn.SharedInstance.SignOutUser ();

                // Clear signed in app state
                currentAuth = null;
                Root[1].Clear ();
                ToggleAuthUI ();
            });
            signinButton = new SignInButtonElement ();

            Root = new RootElement ("Sign In Migration") {
                new Section {
                    signinButton,
                    status,
                },
                new Section {
                },
            };

            ToggleAuthUI ();
        }
 public void Finished(Google.OpenSource.OAuth2Authentication auth, NSError error)
 {
     InvokeOnMainThread(async delegate {
         try {
             if (error == null)
             {
                 IsAuthenticating = true;
                 var token        = Google.Plus.SignIn.SharedInstance.Authentication.AccessToken;
                 var authManager  = ServiceContainer.Resolve <AuthManager> ();
                 var authRes      = await authManager.AuthenticateWithGoogle(token);
                 // No need to keep the users Google account access around anymore
                 Google.Plus.SignIn.SharedInstance.Disconnect();
                 if (authRes != AuthResult.Success)
                 {
                     var email = Google.Plus.SignIn.SharedInstance.Authentication.UserEmail;
                     AuthErrorAlert.Show(this, email, authRes, AuthErrorAlert.Mode.Login, googleAuth: true);
                 }
                 else
                 {
                     // Start the initial sync for the user
                     ServiceContainer.Resolve <ISyncManager> ().Run(SyncMode.Full);
                 }
             }
             else
             {
                 new UIAlertView("WelcomeGoogleErrorTitle".Tr(), "WelcomeGoogleErrorMessage".Tr(), null, "WelcomeGoogleErrorOk".Tr(), null).Show();
             }
         } catch (InvalidOperationException ex) {
             var log = ServiceContainer.Resolve <ILogger> ();
             log.Info(Tag, ex, "Failed to authenticate (G+) the user.");
         } finally {
             IsAuthenticating = false;
         }
     });
 }
Beispiel #3
0
        public void Finished(Google.OpenSource.OAuth2Authentication auth, NSError error)
        {
            InvokeOnMainThread(async delegate {
                try {
                    if (error == null)
                    {
                        IsAuthenticating = true;

                        var token = Google.Plus.SignIn.SharedInstance.Authentication.AccessToken;

                        var authManager = ServiceContainer.Resolve <AuthManager> ();
                        var authRes     = await authManager.SignupWithGoogle(token);

                        // No need to keep the users Google account access around anymore
                        Google.Plus.SignIn.SharedInstance.Disconnect();

                        if (authRes != AuthResult.Success)
                        {
                            var email = Google.Plus.SignIn.SharedInstance.Authentication.UserEmail;
                            AuthErrorAlert.Show(this, email, authRes, AuthErrorAlert.Mode.Signup, googleAuth: true);
                        }
                    }
                    else
                    {
                        new UIAlertView(
                            "WelcomeGoogleErrorTitle".Tr(),
                            "WelcomeGoogleErrorMessage".Tr(),
                            null, "WelcomeGoogleErrorOk".Tr(), null).Show();
                    }
                } finally {
                    IsAuthenticating = false;
                }
            });
        }
        public void DidSignIn(SignIn signIn, GoogleUser user, NSError error)
        {
            // Perform any operations on signed in user here.
            if (user != null && error == null) {

                // VERY IMPORTANT: We create an OAuth2Authentication instance here
                // to use later with the google plus API since it expects this old
                // type of object
                currentAuth = new Google.OpenSource.OAuth2Authentication {
                    ClientId = signIn.ClientID,
                    AccessToken = user.Authentication.AccessToken,
                    ExpirationDate = user.Authentication.AccessTokenExpirationDate,
                    RefreshToken = user.Authentication.RefreshToken,
                    TokenURL = new NSUrl ("https://accounts.google.com/o/oauth2/token")
                };

                // Start fetching the signed in user's info
                GetUserInfo ();

                status.Caption = string.Format ("{0} (Tap to Sign Out)", user.Profile.Name);

                ToggleAuthUI ();
            }
        }
Beispiel #5
0
        public void DidSignIn(SignIn signIn, GoogleUser user, NSError error)
        {
            // Perform any operations on signed in user here.
            if (user != null && error == null)
            {
                // VERY IMPORTANT: We create an OAuth2Authentication instance here
                // to use later with the google plus API since it expects this old
                // type of object
                currentAuth = new Google.OpenSource.OAuth2Authentication {
                    ClientId       = signIn.ClientID,
                    AccessToken    = user.Authentication.AccessToken,
                    ExpirationDate = user.Authentication.AccessTokenExpirationDate,
                    RefreshToken   = user.Authentication.RefreshToken,
                    TokenURL       = new NSUrl("https://accounts.google.com/o/oauth2/token")
                };

                // Start fetching the signed in user's info
                GetUserInfo();

                status.Caption = string.Format("{0} (Tap to Sign Out)", user.Profile.Name);

                ToggleAuthUI();
            }
        }
 public virtual void DidDisconnect(SignIn signIn, GoogleUser user, NSError error)
 {
     currentAuth = null;
     Root [1].Clear ();
     ToggleAuthUI ();
 }
Beispiel #7
0
 public virtual void DidDisconnect(SignIn signIn, GoogleUser user, NSError error)
 {
     currentAuth = null;
     Root [1].Clear();
     ToggleAuthUI();
 }