コード例 #1
0
        private void LoginWithFirebase(GoogleSignInAccount account)
        {
            usingFirebase = true;
            var credentials = GoogleAuthProvider.GetCredential(account.IdToken, null);

            firebaseAuth.SignInWithCredential(credentials).AddOnSuccessListener(this).AddOnFailureListener(this);
        }
コード例 #2
0
        private void FirebaseAuthWithGoogle(GoogleSignInAccount acct)
        {
            //Google Credential
            AuthCredential credential = GoogleAuthProvider.GetCredential(acct.IdToken, null);

            _auth.SignInWithCredential(credential).AddOnCompleteListener(this, this);
        }
コード例 #3
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!");
            }
        }
コード例 #4
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (requestCode == REQUEST_GOOGLE_FITNESS_AUTH)
            {
                authInProgress = false;
                HasGoogleFitnessAuthentication = resultCode == Result.Ok;
                System.Diagnostics.Debug.WriteLine($"Result after auth is: {HasGoogleFitnessAuthentication}");
                GoogleFitnessAuthenticationUpdated?.Invoke(HasGoogleFitnessAuthentication);
            }

            if (requestCode == REQUEST_GOOGLE_SIGN_IN)
            {
                googleLoginInProgress = false;
                var signInTask = GoogleSignIn.GetSignedInAccountFromIntent(data);
                if (signInTask.IsSuccessful)
                {
                    account = (GoogleSignInAccount)signInTask.Result;
                    RequestFitnessPermissions();
                }
            }

            if (requestCode == REQUEST_FITNESS_PERMISSIONS)
            {
                HasGoogleFitnessPermissions = resultCode == Result.Ok;
                GoogleFitnessPermissionsUpdated?.Invoke(HasGoogleFitnessPermissions);
            }
        }
コード例 #5
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == PickImageId)
            {
                if ((resultCode == Result.Ok) && (data != null))
                {
                    Android.Net.Uri  uri    = data.Data;
                    System.IO.Stream stream = ContentResolver.OpenInputStream(uri);
                    PickImageTaskCompletionSource.SetResult(stream);
                }
                else
                {
                    PickImageTaskCompletionSource.SetResult(null);
                }
            }
            if (requestCode == 1)
            {
                GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                if (result.IsSuccess)
                {
                    GoogleSignInAccount account = result.SignInAccount;

                    LoginWithFirebase(account);
                }
            }
        }
コード例 #6
0
ファイル: GoogleLogin.cs プロジェクト: axiomiety/c4c_t4i
        private void FirebaseAuthWithGoogle(GoogleSignInAccount acct)
        {
            Log.Debug(Tag, "FirebaseAuthWithGoogle:" + acct.Id);
            AuthCredential credential = GoogleAuthProvider.GetCredential(acct.IdToken, null);

            mAuth.SignInWithCredential(credential).AddOnCompleteListener(this, this);
        }
コード例 #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            DependencyService.Register <ILocalize, Localize>();
            DependencyService.Register <IAuthRepository, AuthRepository>();

            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Forms.Init(this, savedInstanceState);

            LocalNotificationsImplementation.NotificationIconId = Resource.Drawable.ic_stat_futurelife;
            ImageCircleRenderer.Init();
            Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);

            GoogleSignInAccount account = GoogleSignIn.GetLastSignedInAccount(this);

            if (account == null)
            {
                ConfigureGoogleSignIn();
                GoogleSignInLaunch();
            }
            LoadApplication(new App());
        }
コード例 #8
0
ファイル: MainActivity.cs プロジェクト: marekc73/ShopNaviStd
        private GoogleProfile HandleSignInResult(GoogleSignInResult result)
        {
            GoogleProfile googleProfile = null;

            if (result.IsSuccess)
            {
                // Signed in successfully, show authenticated UI.
                GoogleSignInAccount acct = result.SignInAccount;
                googleProfile = new GoogleProfile()
                {
                    GivenName  = acct.GivenName,
                    FamilyName = acct.FamilyName,
                    Email      = acct.Email,
                    Id         = acct.Id
                };

                //HttpClient client = new HttpClient();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("The resul was not success");
            }

            return(googleProfile);
        }
コード例 #9
0
        public override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            try
            {
                if (requestCode == 1)
                {
                    GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                    if (result.IsSuccess)
                    {
                        GoogleSignInAccount account = result.SignInAccount;
                        string gClientId            = AppController.Globals.GoogleClientId_Android;
                        string gEmail = account.Email;
                        string gToken = account.IdToken;

                        _cts0 = new CancellationTokenSource();
                        AppController.LoginUser(_cts0, gClientId, gEmail, gToken,
                                                (d) =>
                        {
                            AppController.Settings.LastLoginUserIdUsed   = d.UserId;
                            AppController.Settings.LastLoginUsernameUsed = _email;
                            AppController.Settings.AuthAccessToken       = d.AuthAccessToken;
                            AppController.Settings.AuthExpirationDate    = d.AuthExpirationDate.GetValueOrDefault().ToLocalTime();
                            AppController.Settings.GoogleSignedIn        = true;

                            var f = new GimmicksFragment();
                            this.FragmentManager.BeginTransaction()
                            .AddToBackStack("BeforeGimmicksFragment")
                            .Replace(Resource.Id.ContentLayout, f, "GimmicksFragment")
                            .Commit();
                        },
                                                (error) =>
                        {
                            Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                        },
                                                () =>
                        {
                            ((MainActivity)this.Activity).UnblockUI();
                        });
                    }
                    else
                    {
                        ((MainActivity)this.Activity).UnblockUI();

                        Toast.MakeText(this.Activity.Application, "Unable to login with Google!", ToastLength.Long).Show();
                    }
                }
            }
            catch (Exception ex)
            {
                ((MainActivity)this.Activity).UnblockUI();

                Toast.MakeText(this.Activity.ApplicationContext, "Error logging with Google!", ToastLength.Long).Show();
            }
            finally
            {
                // Nothing to do
            }
        }
コード例 #10
0
        async Task SyncRealm(GoogleSignInAccount googleAccount)
        {
            try
            {
                var user = await User.LoginAsync(Credentials.Google(googleAccount.IdToken),
                                                 new Uri("http://realm_object_server_url:port/"));

                var config = new SyncConfiguration(user,
                                                   new Uri("realm://realm_object_server_url:port/~/testrealm"))
                {
                    SchemaVersion = 1
                };

                var realm = await Realm.GetInstanceAsync(config);

                var transaction = realm.BeginWrite();
                realm.Add(new TestTable {
                    Name = googleAccount.DisplayName
                });
                transaction.Commit();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
コード例 #11
0
        protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            Log.Debug(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
            if (CallbackManager != null)
            {
                CallbackManager.OnActivityResult(requestCode, (int)resultCode, data);
            }
            if (requestCode == RC_SIGN_IN)
            {
                IsLogin_InProgress(false);
                GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                if (result.IsSuccess)
                {
                    GoogleSignInAccount userAccount = result.SignInAccount;
                    var success = await FirebaseAuthHelper.FirebaseAuthWithGoogle(FirebaseAuth, userAccount);

                    if (success)
                    {
                        Intent mainactivityIntent = new Intent(this, typeof(MainActivity));
                        StartActivity(mainactivityIntent);
                        Finish();
                    }
                }
            }
        }
コード例 #12
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == 99) // google oauth
            {
                GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                if (result.IsSuccess)
                {
                    GoogleSignInAccount account = result.SignInAccount;

                    var properties = new Dictionary <string, string>();
                    properties.Add("access_token", account.IdToken);

                    ShinyHost.Resolve <IOAuthService>().OnOAuthComplete(null,
                                                                        new AuthenticatorCompletedEventArgs(new Account(account.DisplayName, properties)));
                }
                else
                {
                    if (result.Status.StatusCode == 12501)
                    {
                        ShinyHost.Resolve <IOAuthService>().OnOAuthError(null, null);
                    }
                    else
                    {
                        ShinyHost.Resolve <IOAuthService>().OnOAuthError(null, new AuthenticatorErrorEventArgs($"Google OAuth ErrorCode: {result.Status.StatusCode}"));
                    }
                }
            }
            else
            {
                InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data);
            }
        }
コード例 #13
0
 protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
 {
     Log.Debug(TAG, "Sign in result with result code: " + resultCode);
     base.OnActivityResult(requestCode, resultCode, data);
     if (requestCode == 1)
     {
         if (resultCode == Result.Ok)
         {
             GoogleSignInResult res = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
             if (res.IsSuccess)
             {
                 GoogleSignInAccount acct = res.SignInAccount;
                 Log.Debug(TAG, "id:" + acct.Id + " tokenId:" + acct.IdToken);
             }
             else
             {
                 AlertDialog.Builder alg = new AlertDialog.Builder(this);
                 alg.SetTitle("Sign in failed");
                 alg.Show();
             }
         }
         else
         {
             AlertDialog.Builder alg = new AlertDialog.Builder(this);
             alg.SetTitle("Sign in failed");
             alg.Show();
         }
     }
 }
コード例 #14
0
        private async void HandleSignInResult(GoogleSignInResult result)
        {
            if (result.IsSuccess)
            {
                // Signed in successfully, show authenticated UI.
                ProgressDialog      progressDialog = ProgressDialog.Show(this, "", "Retrieving profile data", true);
                GoogleSignInAccount acct           = result.SignInAccount;
                await MeritMoneyBrain.SingInWithGoogle(acct.IdToken);

                Profile profile = await MeritMoneyBrain.GetProfile();

                Intent returnIntent = new Intent();
                returnIntent.PutExtra(GetString(Resource.String.LogIn), true);
                SetResult(Result.Ok, returnIntent);
                await new SaveData().Execute(profile).GetAsync();
                progressDialog.Dismiss();
                Finish();
                //updateUI(true);
            }
            else
            {
                // Signed out, show unauthenticated UI.
                //updateUI(false);
            }
        }
コード例 #15
0
        void handleSignInResult(GoogleSignInResult result)
        {
            //Log.d (TAG, "handleSignInResult:" + result.isSuccess ());
            if (result.IsSuccess)
            {
                // Signed in successfully, show authenticated UI.
                GoogleSignInAccount user = result.SignInAccount;

                if (user != null)
                {
                    Log.Debug($"user.Account.Name: {user.Account.Name}");
                    Log.Debug($"acct.DisplayName: {user.DisplayName}");
                    Log.Debug($"acct.Email: {user.Email}");
                    Log.Debug($"acct.FamilyName: {user.FamilyName}");
                    Log.Debug($"acct.GivenName: {user.GivenName}");
                    Log.Debug($"acct.GrantedScopes: {string.Join (",", user.GrantedScopes)}");
                    Log.Debug($"acct.Id: {user.Id}");
                    Log.Debug($"acct.IdToken: {user.IdToken}");
                    Log.Debug($"acct.PhotoUrl: {user.PhotoUrl}");
                    Log.Debug($"acct.ServerAuthCode: {user.ServerAuthCode}");

                    ClientAuthManager.Shared.SetClientAuthDetails(user.GetAuthDetails());
                    Finish();
                }
            }
            else
            {
                // Signed out, show unauthenticated UI.
                Log.Debug($"Google SingIn failed with code:{result.Status}");
            }
        }
コード例 #16
0
        void LoginWithFirebaseAccount(GoogleSignInAccount acc)
        {
            var credentials = GoogleAuthProvider.GetCredential(acc.IdToken, null);

            FireAuth.SignInWithCredential(credentials)
            .AddOnSuccessListener(this)
            .AddOnFailureListener(this);
        }
コード例 #17
0
 private void setAccountDetailsAsUser(GoogleSignInAccount details)
 {
     currentUser            = new User();
     currentUser.email      = details.Email;
     currentUser.firstName  = details.DisplayName;
     currentUser.lastName   = details.FamilyName;
     StaticAuth.currentUser = currentUser;
 }
コード例 #18
0
        public void HandleSignIn(GoogleSignInResult result)
        {
            GoogleSignInAccount account = null;

            if (result.IsSuccess)
            {
                account = result.SignInAccount;
            }
        }
コード例 #19
0
 protected override void OnCreate(Bundle savedInstanceState)
 {
     mGoogleSignInAccount = (GoogleSignInAccount)Intent.GetParcelableExtra("SignInAccount");
     ToolbarResource      = Resource.Layout.Toolbar;
     TabLayoutResource    = Resource.Layout.Tabbar;
     base.OnCreate(savedInstanceState);
     global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
     LoadApplication(new App());
 }
コード例 #20
0
ファイル: MainActivity.cs プロジェクト: gorojou/firebaseapp
 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
 {
     base.OnActivityResult(requestCode, resultCode, data);
     if (requestCode == FirebaseAuthService.REQ_AUTH && resultCode == Result.Ok)
     {
         GoogleSignInAccount sg = (GoogleSignInAccount)data.GetParcelableExtra("result");
         MessagingCenter.Send(FirebaseAuthService.KEY_AUTH, FirebaseAuthService.KEY_AUTH, sg.IdToken);
     }
 }
コード例 #21
0
 private void HandleResult(GoogleSignInAccount result)
 {
     if (result != null)
     {
         Intent myIntent = new Intent(this, typeof(GoogleLoginActiviy));
         myIntent.PutExtra("result", result);
         SetResult(Result.Ok, myIntent);
     }
     Finish();
 }
コード例 #22
0
 private void handleSignInResult()
 {
     if (mGoogleSignInResult.IsSuccess)
     {
         mGoogleSignInAccount = mGoogleSignInResult.SignInAccount;
         var forms = new Intent(this, typeof(FormsActivity));
         forms.PutExtra("SignInAccount", mGoogleSignInAccount);
         StartActivity(forms);
     }
 }
コード例 #23
0
            public void OnSuccess(Java.Lang.Object signInAccount)
            {
                GoogleSignInAccount googleSignInAccount = (GoogleSignInAccount)signInAccount;
                string authCode = googleSignInAccount.ServerAuthCode;

                Log.Debug("GooglePlaySignInListener", "Successfuly. Auth code: " + authCode);
                IAGConnectAuthCredential credential = GoogleGameAuthProvider.CredentialWithToken(authCode);

                loginActivity.SignIn(credential);
            }
コード例 #24
0
            public void OnSuccess(Java.Lang.Object signInAccount)
            {
                GoogleSignInAccount googleSignInAccount = (GoogleSignInAccount)signInAccount;
                string idToken = googleSignInAccount.IdToken;

                Log.Debug("GoogleSignInlistener", "Successfuly. Access token: " + idToken);
                IAGConnectAuthCredential credential = GoogleAuthProvider.CredentialWithToken(idToken);

                loginActivity.SignIn(credential);
            }
コード例 #25
0
 public void OnAuthCompleted(object result)
 {
     if (((GoogleSignInResult)result).IsSuccess)
     {
         GoogleSignInAccount account = ((GoogleSignInResult)result).SignInAccount;
         _onLoginComplete?.Invoke(CurrentUser, string.Empty);
     }
     else
     {
         _onLoginComplete?.Invoke(null, "An error occured!");
     }
 }
コード例 #26
0
 void OnSignInResult(Result resultCode, Intent data)
 {
     Activity1.Instance.UnRegisterActivityResultHandler(Activity1.RC_SIGN_IN, OnSignInResult);
     if (resultCode == Result.Ok)
     {
         GoogleSignInResult  result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
         GoogleSignInAccount acct   = result.SignInAccount;
         ((GoogleAuth_Android)_instance).m_szEmail = acct.Email;
         ((GoogleAuth_Android)_instance).m_szId    = acct.IdToken;
     }
     m_WaitingForAuth = false;
 }
コード例 #27
0
 protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data)
 {
     base.OnActivityResult(requestCode, resultCode, data);
     //GoogleClientManager.OnAuthCompleted(requestCode, resultCode, data);
     if (requestCode == 9001)
     {
         var result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
         if (result.IsSuccess)
         {
             GoogleSignInAccount accountDetails = result.SignInAccount;
             Toast.MakeText(this, accountDetails.IdToken, ToastLength.Long).Show();
         }
     }
 }
コード例 #28
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == 1)
            {
                GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                if (result.IsSuccess)
                {
                    GoogleSignInAccount account = result.SignInAccount;
                    LoginWithGoogle(account);
                }
            }
        }
コード例 #29
0
        private void LoginWithGoogle(GoogleSignInAccount account)
        {
            User user = new User();

            user.Fullname  = account.DisplayName;
            user.Email     = account.Email;
            user.imagepath = account.PhotoUrl.ToString();

            Intent secondpageintent = new Intent(this, typeof(SecondPageActivity));

            secondpageintent.PutExtra("accepteduser", JsonConvert.SerializeObject(user));
            StartActivity(secondpageintent);
            return;
        }
コード例 #30
0
 private void HandleSignInResult(GoogleSignInResult googleResult)
 {
     if (googleResult.IsSuccess)
     {
         try
         {
             // Google Sign In was successful, authenticate with Firebase
             GoogleSignInAccount account = googleResult.SignInAccount;
             FirebaseAuthWithGoogle(account);
         }
         catch (ApiException e)
         {
         }
     }
 }