private void LoginWithFirebase(GoogleSignInAccount account)
        {
            usingFirebase = true;
            var credentials = GoogleAuthProvider.GetCredential(account.IdToken, null);

            firebaseAuth.SignInWithCredential(credentials).AddOnSuccessListener(this).AddOnFailureListener(this);
        }
        private void handleFacebookAccessToken(AccessToken accessToken)
        {
            //Facebook Credential
            AuthCredential credential = FacebookAuthProvider.GetCredential(accessToken.Token);

            _auth.SignInWithCredential(credential).AddOnCompleteListener(this, this);
        }
Ejemplo n.º 3
0
        public static async Task AuthWithFacebookAsync(AccessToken token)
        {
            var credential = FacebookAuthProvider.GetCredential(token.Token);

            CurrentFirebaseInstance.SignInWithCredential(credential);
            var user = CurrentFirebaseInstance.CurrentUser;

            QSN.Helpers.Settings.UserId = user.Uid;
            var tokenObject = await user.GetIdTokenAsync(false);

            QSN.Helpers.Settings.UserToken = tokenObject.Token;

            QSN.Helpers.Settings.UserImage = user.ProviderData.FirstOrDefault((x) => x.ProviderId == "facebook.com").PhotoUrl.ToString();
            QSN.Helpers.Settings.UserName  = user.DisplayName;

            Xamarin.Forms.Application.Current.MainPage = new Xamarin.Forms.MasterDetailPage()
            {
                Master = new MasterPage()
                {
                    Title = "Main Page"
                },
                Detail = new Xamarin.Forms.NavigationPage(new QuotesPage())
            };

            //Use, if email needed

            //GraphRequest request = GraphRequest.NewMeRequest(token, new GraphJsonCallback());

            //Bundle parameters = new Bundle();
            //request.Parameters.PutString("fields", "id,name,link,email");
            //request.ExecuteAsync();
        }
Ejemplo n.º 4
0
        private void FirebaseAuthWithGoogle(GoogleSignInAccount acct)
        {
            Log.Debug(Tag, "FirebaseAuthWithGoogle:" + acct.Id);
            AuthCredential credential = GoogleAuthProvider.GetCredential(acct.IdToken, null);

            mAuth.SignInWithCredential(credential).AddOnCompleteListener(this, this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sign into Firebase with credentials
        /// </summary>
        /// <param name="phoneAuthCredential">Credentials used to sign into Firebase</param>
        private void SignIn(PhoneAuthCredential phoneAuthCredential)
        {
            FirebaseAuth auth = new FirebaseAuth(FirebaseApp.Instance);

            // Sign into Firebase with callback
            auth.SignInWithCredential(phoneAuthCredential).AddOnCompleteListener(Activity, this);
        }
Ejemplo n.º 6
0
        private void InitializeCredentials(PhoneAuthCredential credential)
        {
            SessionManager sessionManager = SessionManager.GetInstance();

            mAuth = sessionManager.GetFirebaseAuth();
            mAuth.SignInWithCredential(credential)
            .AddOnCompleteListener(this)
            .AddOnFailureListener(this);
        }
        private void SignInWithPhoneAuthCredential(PhoneAuthCredential credential)
        {
            TaskCompletionListener taskCompletionListener = new TaskCompletionListener();

            taskCompletionListener.Success += TaskCompletionListener_Success;
            taskCompletionListener.Failure += TaskCompletionListener_Failure;

            mAuth.SignInWithCredential(credential)
            .AddOnSuccessListener(taskCompletionListener)
            .AddOnFailureListener(taskCompletionListener);
        }
Ejemplo n.º 8
0
        private void FacebookAuthComplete(object sender, AuthenticatorCompletedEventArgs e)
        {
            Log.Debug(Tag, "FacebookAuthComplete:" + e.IsAuthenticated);

            if (e.IsAuthenticated)
            {
                var            token      = e.Account.Properties["access_token"];
                AuthCredential credential = FacebookAuthProvider.GetCredential(token);
                mAuth.SignInWithCredential(credential);
            }
        }
Ejemplo n.º 9
0
        private void TwitterAuthComplete(object sender, AuthenticatorCompletedEventArgs e)
        {
            Log.Debug(Tag, "TwitterAuthComplete:" + e.IsAuthenticated);

            if (e.IsAuthenticated)
            {
                var token  = e.Account.Properties["oauth_token"];
                var secret = e.Account.Properties["oauth_token_secret"];

                AuthCredential credential = TwitterAuthProvider.GetCredential(token, secret);
                mAuth.SignInWithCredential(credential);
            }
        }
Ejemplo n.º 10
0
        private void VerifyCode(string code)
        {
            OnboardingActivity.ShowLoader();
            PhoneAuthCredential cred = PhoneAuthProvider.GetCredential(verificationId, code);

            auth.SignInWithCredential(cred)
            .AddOnCompleteListener(new OncompleteListener(
                                       onComplete: (t) =>
            {
                try
                {
                    switch (t.IsSuccessful)
                    {
                    case false:
                        throw t.Exception;

                    default:
                        CheckUserAvailability();
                        break;
                    }
                }
                catch (FirebaseAuthInvalidCredentialsException fiace)
                {
                    OnboardingActivity.DismissLoader();
                    OnboardingActivity.ShowError(fiace.Source, fiace.Message);
                }
                catch (FirebaseTooManyRequestsException ftmre)
                {
                    OnboardingActivity.DismissLoader();
                    OnboardingActivity.ShowError(ftmre.Source, ftmre.Message);
                }
                catch (FirebaseAuthInvalidUserException fiue)
                {
                    OnboardingActivity.DismissLoader();
                    OnboardingActivity.ShowError(fiue.Source, fiue.Message);
                }
                catch (FirebaseNetworkException)
                {
                    OnboardingActivity.DismissLoader();
                    OnboardingActivity.ShowNoNetDialog(false);
                }
                catch (Exception e)
                {
                    OnboardingActivity.DismissLoader();
                    OnboardingActivity.ShowError(e.Source, e.Message);
                }
            }));
        }
Ejemplo n.º 11
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);
            // check if the user is signed in
            FirebaseAuth mAuth2      = FirebaseAuth.Instance;
            FirebaseUser currentUser = mAuth2.CurrentUser;

            if (currentUser != null)
            {
                silentSignIn = true;
                // signed into Firebase, so get the token and save it in user object
                if (AppManager.User == null)
                {
                    AppManager.User        = new UserDetails();
                    AppManager.User.UserId = currentUser.Uid;
                    var tokenResult = currentUser.GetToken(false);
                    tokenResult.AddOnSuccessListener(this);
                }
                else
                {
                    if (!publishLoginDone)
                    {
                        Xamarin.Forms.MessagingCenter.Send("NavigateToNextPage", "LoginDone");
                        publishLoginDone = true;
                    }

                    AppManager.GetFavoritesFromFirebase(AppManager.User.UserId);
                }
            }
            else
            {
                try
                {
                    var                    credential   = TwitterAuthProvider.GetCredential(App.token, App.tokensecret);
                    FirebaseAuth           mAuth        = FirebaseAuth.Instance;
                    Android.Gms.Tasks.Task signedInTask = mAuth.SignInWithCredential(credential);
                    signedInTask.AddOnCompleteListener(this);
                }
                catch (Exception ex)
                {
                    string j = ex.Message;
                }
            }
        }
Ejemplo n.º 12
0
        public void OnSuccess(Object result)
        {
            if (!usingFirebase)
            {
                usingFirebase = true;
                LoginResult loginResult = result as LoginResult;
                var         credentials = FacebookAuthProvider.GetCredential(loginResult.AccessToken.Token);
                firebaseAuth.SignInWithCredential(credentials).AddOnSuccessListener(this)
                .AddOnFailureListener(this);
            }
            else
            {
                Toast.MakeText(this, "Login successful", ToastLength.Short).Show();
                usingFirebase = false;

                emailText.Text    = firebaseAuth.CurrentUser.Email;
                usernameText.Text = firebaseAuth.CurrentUser.DisplayName;
            }
        }
        public void OnSuccess(Java.Lang.Object result)
        {
            if (!usingFirebase)
            {
                dialogHelper.ShowDialog();
                usingFirebase = true;
                loginResult   = result as LoginResult;

                var credentials = FacebookAuthProvider.GetCredential(loginResult.AccessToken.Token);
                auth.SignInWithCredential(credentials)
                .AddOnSuccessListener(this, this)
                .AddOnFailureListener(this, this);
            }
            else
            {
                usingFirebase = false;
                userID        = auth.CurrentUser.Uid;
                CheckIfUserExists();
            }
        }