private void onGoogleSignInResult(Intent data)
        {
            lock (lockable)
            {
                var signInData = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                if (!signInData.IsSuccess)
                {
                    loginSubject.OnError(new GoogleLoginException(signInData.Status.IsCanceled));
                    isLoggingIn = false;
                    return;
                }

                Task.Run(() =>
                {
                    try
                    {
                        var token = GoogleAuthUtil.GetToken(Application.Context, signInData.SignInAccount.Account, scope);
                        loginSubject.OnNext(token);
                        loginSubject.OnCompleted();
                    }
                    catch (Exception e)
                    {
                        loginSubject.OnError(e);
                    }
                    finally
                    {
                        isLoggingIn = false;
                    }
                });
            }
        }
Ejemplo n.º 2
0
        public void OnAuthCompleted(GoogleSignInResult result)
        {
            GoogleUser googleUser = new GoogleUser();

            if (result.IsSuccess)
            {
                Task.Factory.StartNew(() => {
                    if (result.SignInAccount.Account == null)
                    {
                        MessagingCenter.Send <string>("access token bilgisi alınamadı", "NoInternet");
                    }
                    var accessToken        = GoogleAuthUtil.GetToken(Android.App.Application.Context, result.SignInAccount.Email, $"oauth2:{Scopes.Email} {Scopes.Profile}");
                    googleUser.AccessToken = accessToken;
                    MessagingCenter.Send <string>(accessToken, "googleAndroidAccessToken");
                });
                GoogleSignInAccount accountt = result.SignInAccount;
                googleUser.Email       = accountt.Email;
                googleUser.Name        = accountt.GivenName;
                googleUser.Surname     = accountt.FamilyName;
                googleUser.AccessToken = accountt.IdToken;
                //googleUser.Token = accountt.IdToken;

                googleUser.Picture = new Uri((accountt.PhotoUrl != null ? $"{accountt.PhotoUrl}" : $"https://autisticdating.net/imgs/profile-placeholder.jpg"));
                _onLoginComplete?.Invoke(googleUser, string.Empty);
            }
            else
            {
                _onLoginComplete?.Invoke(null, "An error occured!");
            }
        }
Ejemplo n.º 3
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == 1000 && resultCode == Result.Ok)
            {
                var     accountName    = data.GetStringExtra(AccountManager.KeyAccountName);
                Account accountDetails = new Account(accountName, GoogleAuthUtil.GoogleAccountType);

                //var accountId = GoogleAuthUtil.GetAccountId(this, accountName);
                var token = GoogleAuthUtil.GetToken(this, accountDetails, "oauth2:mail");//https://www.googleapis.com/auth/drive.file
            }

            if (requestCode == 500 && resultCode == Result.Ok)
            {
                GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                GoogleManager.Drive(result.SignInAccount);
            }
        }
Ejemplo n.º 4
0
        protected override void ProcessMvxIntentResult(MvxIntentResultEventArgs result)
        {
            base.ProcessMvxIntentResult(result);

            if (result.RequestCode != googleSignInResult)
            {
                return;
            }

            lock (lockable)
            {
                var signInData = Auth.GoogleSignInApi.GetSignInResultFromIntent(result.Data);
                if (signInData.IsSuccess)
                {
                    var activity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity as FragmentActivity;

                    Task.Run(() =>
                    {
                        try
                        {
                            var token = GoogleAuthUtil.GetToken(activity, signInData.SignInAccount.Account, scope);
                            subject.OnNext(token);
                            subject.OnCompleted();
                        }
                        catch (Exception e)
                        {
                            subject.OnError(e);
                        }
                        finally
                        {
                            isLoggingIn = false;
                        }
                    });
                }
                else
                {
                    subject.OnError(new GoogleLoginException(signInData.Status.IsCanceled));
                    isLoggingIn = false;
                }
            }
        }
Ejemplo n.º 5
0
        protected override void ProcessMvxIntentResult(MvxIntentResultEventArgs result)
        {
            base.ProcessMvxIntentResult(result);

            if (result.RequestCode != googleSignInResult)
            {
                return;
            }

            lock (lockable)
            {
                var signInData = Auth.GoogleSignInApi.GetSignInResultFromIntent(result.Data);
                if (signInData.IsSuccess)
                {
                    Task.Run(() =>
                    {
                        try
                        {
                            var token = GoogleAuthUtil.GetToken(Application.Context, signInData.SignInAccount.Account, scope);
                            loginSubject.OnNext(token);
                            loginSubject.OnCompleted();
                        }
                        catch (Exception e)
                        {
                            loginSubject.OnError(e);
                        }
                        finally
                        {
                            isLoggingIn = false;
                        }
                    });
                }
                else
                {
                    loginSubject.OnError(new GoogleLoginException(signInData.Status.IsCanceled));
                    isLoggingIn = false;
                }
            }
        }
Ejemplo n.º 6
0
            private async void StartAuth()
            {
                if (IsAuthenticating)
                {
                    return;
                }
                IsAuthenticating = true;

                LoginActivity activity;

                try {
                    var log         = ServiceContainer.Resolve <Logger> ();
                    var authManager = ServiceContainer.Resolve <AuthManager> ();
                    var ctx         = Activity;

                    // Workaround for Android linker bug which forgets to register JNI types
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GoogleAuthException", typeof(GoogleAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GooglePlayServicesAvailabilityException", typeof(GooglePlayServicesAvailabilityException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableAuthException", typeof(UserRecoverableAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableNotifiedException", typeof(UserRecoverableNotifiedException));

                    String token = null;
                    try {
                        token = await Task.Factory.StartNew(() => GoogleAuthUtil.GetToken(ctx, Email, GoogleOAuthScope));
                    } catch (GooglePlayServicesAvailabilityException exc) {
                        var dia = GooglePlayServicesUtil.GetErrorDialog(
                            exc.ConnectionStatusCode, ctx, GoogleAuthRequestCode);
                        dia.Show();
                    } catch (UserRecoverableAuthException exc) {
                        StartActivityForResult(exc.Intent, GoogleAuthRequestCode);
                    } catch (Java.IO.IOException exc) {
                        // Connectivity error.. nothing to do really?
                        log.Info(Tag, exc, "Failed to login with Google due to network issues.");
                    } catch (Exception exc) {
                        log.Error(Tag, exc, "Failed to get access token for '{0}'.", Email);
                    }

                    // Failed to get token
                    if (token == null)
                    {
                        return;
                    }

                    activity = Activity as LoginActivity;
                    if (activity != null && activity.CurrentMode == Mode.Signup)
                    {
                        // Signup with Google
                        var success = await authManager.SignupWithGoogle(token);

                        if (!success)
                        {
                            GoogleAuthUtil.InvalidateToken(ctx, token);

                            new SignupFailedDialogFragment().Show(FragmentManager, "invalid_credentials_dialog");
                        }
                    }
                    else
                    {
                        // Authenticate client
                        var success = await authManager.AuthenticateWithGoogle(token);

                        if (!success)
                        {
                            GoogleAuthUtil.InvalidateToken(ctx, token);

                            new NoAccountDialogFragment().Show(FragmentManager, "invalid_credentials_dialog");
                        }
                    }
                } finally {
                    IsAuthenticating = false;
                }

                // Clean up self:
                if (Activity != null)
                {
                    FragmentManager.BeginTransaction()
                    .Remove(this)
                    .Commit();
                }

                // Try to make the activity recheck auth status
                activity = Activity as LoginActivity;
                if (activity != null)
                {
                    activity.StartAuthActivity();
                }
            }
Ejemplo n.º 7
0
            private async Task StartAuthAsync()
            {
                if (IsAuthenticating)
                {
                    return;
                }
                IsAuthenticating = true;

                try {
                    var log         = ServiceContainer.Resolve <ILogger> ();
                    var authManager = ServiceContainer.Resolve <AuthManager> ();
                    var ctx         = Activity;

                    // No point in trying to reauth when old authentication is still running.
                    if (authManager.IsAuthenticating)
                    {
                        return;
                    }

                    // Workaround for Android linker bug which forgets to register JNI types
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GoogleAuthException", typeof(GoogleAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GooglePlayServicesAvailabilityException", typeof(GooglePlayServicesAvailabilityException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableAuthException", typeof(UserRecoverableAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableNotifiedException", typeof(UserRecoverableNotifiedException));

                    String token = null;
                    try {
                        token = await Task.Factory.StartNew(() => GoogleAuthUtil.GetToken(ctx, Email, GoogleOAuthScope));
                    } catch (GooglePlayServicesAvailabilityException exc) {
                        var dia = GooglePlayServicesUtil.GetErrorDialog(
                            exc.ConnectionStatusCode, ctx, GoogleAuthRequestCode);
                        dia.Show();
                    } catch (UserRecoverableAuthException exc) {
                        StartActivityForResult(exc.Intent, GoogleAuthRequestCode);
                    } catch (Java.IO.IOException exc) {
                        // Connectivity error.. nothing to do really?
                        log.Info(LogTag, exc, "Failed to login with Google due to network issues.");
                    } catch (Exception exc) {
                        log.Error(LogTag, exc, "Failed to get access token for '{0}'.", Email);
                    }

                    // Failed to get token
                    if (token == null)
                    {
                        return;
                    }

                    try {
                        var authRes = await viewModel.TrySignupGoogleAsync(token);

                        if (authRes != AuthResult.Success)
                        {
                            ClearGoogleToken(ctx, token);
                            var dia = new ErrorDialogFragment(authRes);
                            dia.Show(FragmentManager, "auth_result_dialog");
                        }
                    } catch (InvalidOperationException ex) {
                        log.Info(LogTag, ex, "Failed to authenticate user with Google login.");
                    }
                } finally {
                    IsAuthenticating = false;
                }

                // Clean up self:
                if (Activity != null)
                {
                    FragmentManager.BeginTransaction()
                    .Remove(this)
                    .Commit();
                }
            }
Ejemplo n.º 8
0
            private async Task StartAuthAsync()
            {
                LoginActivity activity;

                try {
                    var log         = ServiceContainer.Resolve <ILogger> ();
                    var authManager = ServiceContainer.Resolve <AuthManager> ();
                    var ctx         = Activity;

                    // No point in trying to reauth when old authentication is still running.
                    if (authManager.IsAuthenticating)
                    {
                        return;
                    }

                    // Workaround for Android linker bug which forgets to register JNI types
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GoogleAuthException", typeof(GoogleAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GooglePlayServicesAvailabilityException", typeof(GooglePlayServicesAvailabilityException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableAuthException", typeof(UserRecoverableAuthException));
                    Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableNotifiedException", typeof(UserRecoverableNotifiedException));

                    String token = null;
                    try {
                        var account = AccountManager.Get(ctx).GetAccounts()
                                      .Where(x => x.Type == GoogleAuthUtil.GoogleAccountType && x.Name == Email)
                                      .FirstOrDefault();

                        token = await Task.Factory.StartNew(() => GoogleAuthUtil.GetToken(ctx, account, GoogleOAuthScope));
                    } catch (GooglePlayServicesAvailabilityException exc) {
                        var dia = GooglePlayServicesUtil.GetErrorDialog(
                            exc.ConnectionStatusCode, ctx, GoogleAuthRequestCode);
                        dia.Show();
                    } catch (UserRecoverableAuthException exc) {
                        StartActivityForResult(exc.Intent, GoogleAuthRequestCode);
                    } catch (Java.IO.IOException exc) {
                        // Connectivity error.. nothing to do really?
                        log.Info(LogTag, exc, "Failed to login with Google due to network issues.");
                    } catch (Exception exc) {
                        log.Error(LogTag, exc, "Failed to get access token for '{0}'.", Email);
                    }

                    // Failed to get token
                    if (token == null)
                    {
                        return;
                    }

                    try {
                        activity = Activity as LoginActivity;
                        if (activity != null && activity.CurrentMode == Mode.Signup)
                        {
                            // Signup with Google
                            var authRes = await activity.SignupWithGoogle(token);

                            if (authRes != AuthResult.Success)
                            {
                                ClearGoogleToken(ctx, token);
                                activity.ShowAuthError(Email, authRes, Mode.Signup, true);
                            }
                        }
                        else
                        {
                            // Authenticate client
                            var authRes = await authManager.AuthenticateWithGoogleAsync(token);

                            if (authRes != AuthResult.Success)
                            {
                                ClearGoogleToken(ctx, token);
                                activity.ShowAuthError(Email, authRes, Mode.Login, true);
                            }
                        }
                    } catch (InvalidOperationException ex) {
                        log.Info(LogTag, ex, "Failed to authenticate user with Google login.");
                    }
                } catch (Exception e) {
                }

                // Clean up self:
                if (Activity != null)
                {
                    FragmentManager.BeginTransaction()
                    .Remove(this)
                    .Commit();
                }
            }