Example #1
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);
        }
Example #2
0
 public static IAuthCredential Create(AuthCredential authCredential)
 {
     return(authCredential switch
     {
         OAuthCredential oAuthCredential => new OAuthCredentialWrapper(oAuthCredential),
         PhoneAuthCredential phoneAuthCredential => new PhoneAuthCredentialWrapper(phoneAuthCredential),
         _ => new AuthCredentialWrapper(authCredential)
     });
        public void VerifyPhoneNumberWithCode(string verificationId, string code)
        {
            if (verificationId != null)
            {
                PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, code);

                SignInWithPhoneAuthCredential(credential);
            }
        }
            public override void OnVerificationCompleted(PhoneAuthCredential credential)
            {
                var result = new PhoneNumberVerificationResult
                {
                    AuthCredential = credential
                };

                _tcs.SetResult(result);
            }
Example #5
0
        private void InitializeCredentials(PhoneAuthCredential credential)
        {
            SessionManager sessionManager = SessionManager.GetInstance();

            mAuth = sessionManager.GetFirebaseAuth();
            mAuth.SignInWithCredential(credential)
            .AddOnCompleteListener(this)
            .AddOnFailureListener(this);
        }
Example #6
0
        public override void OnVerificationCompleted(PhoneAuthCredential credential)
        {
            var result = new PhoneNumberVerificationResult
            {
                AuthCredential = credential
            };

            _subject.OnNext(result);
            _subject.OnCompleted();
        }
Example #7
0
 public override void OnVerificationCompleted(PhoneAuthCredential credential)
 {
     var cre = credential;
     // This callback will be invoked in two situations:
     // 1 - Instant verification. In some cases the phone number can be instantly
     //     verified without needing to send or enter a verification code.
     // 2 - Auto-retrieval. On some devices Google Play services can automatically
     //     detect the incoming verification SMS and perform verification without
     //     user action.
 }
        public override void OnVerificationCompleted(PhoneAuthCredential credential)
        {
            string strCode = credential.SmsCode;

            if (strCode != null)
            {
                _instance.CodePinView.Value = strCode;
                _instance.VerifyCode(strCode);
                _instance.ShowProgressDialog();
            }
        }
Example #9
0
 public override void OnVerificationCompleted(PhoneAuthCredential p0)
 {
     try
     {
         SignIn(p0);
     }
     catch (Exception mes)
     {
         FirebaseServiceCallBack?.OnVerificationFailed(mes.Message);
     }
 }
        private void SignInWithPhoneAuthCredential(PhoneAuthCredential credential)
        {
            TaskCompletionListener taskCompletionListener = new TaskCompletionListener();

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

            mAuth.SignInWithCredential(credential)
            .AddOnSuccessListener(taskCompletionListener)
            .AddOnFailureListener(taskCompletionListener);
        }
Example #11
0
        public async Task <AuthorizedUser> SignIn(string verificationId, string verificationCode)
        {
            PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, verificationCode);
            var result = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

            return(new AuthorizedUser
            {
                PhoneNumber = result.User.PhoneNumber,
                Uid = result.User.Uid
            });
        }
Example #12
0
 public void VerifyCode(string otpCode)
 {
     try
     {
         PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(VerificationID, otpCode);
         InitializeCredentials(credential);
     }
     catch (IllegalArgumentException iae)
     {
         Log.Debug("illegalArgument on verificationID", iae.Message);
     }
 }
        public async void SignInWithCredential(PhoneAuthCredential credential)
        {
            var firebaseResult = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

            if (firebaseResult != null)
            {
                SetVerificationStatus(VerificationStatus.Success);
            }
            else
            {
                SetVerificationStatus(VerificationStatus.Failed);
            }
        }
Example #14
0
        /*****************************************************************/
        // METHODS
        /*****************************************************************/
        #region Methods

        /// <summary>
        /// Sign into Firebase with credentials
        /// </summary>
        /// <param name="phoneAuthCredential">Credentials used to sign into Firebase</param>
        private void SignIn(PhoneAuthCredential phoneAuthCredential)
        {
            Auth.DefaultInstance.SignInWithCredential(phoneAuthCredential, (authResult, error) =>
            {
                // Error occurred
                if (error != null)
                {
                    FirebaseServiceCallBack?.OnVerificationFailed(error.LocalizedDescription);
                    return;
                }

                // User signed in
                FirebaseServiceCallBack?.SignedIn();
            });
        }
Example #15
0
        public async override void OnVerificationCompleted(PhoneAuthCredential credential)
        {
            var authResult = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

            if (authResult != null)
            {
                var tokenResult = await authResult.User.GetIdTokenAsync(true);

                Debug.WriteLine(tokenResult.Token);
                if (OnVerificationCompletedEvent != null)
                {
                    OnVerificationCompletedEvent(true, tokenResult.Token);
                }
            }
        }
Example #16
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);
                }
            }));
        }
Example #17
0
        public override async void OnVerificationCompleted(PhoneAuthCredential credential)
        {
            if (onSMS)
            {
                onOTPComplete?.Execute(credential.SmsCode);
            }
            else
            {
                var res = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

                if (res.User != null)
                {
                    onVerifyComplete?.Execute(null);
                }
            }
        }
Example #18
0
            public override void OnVerificationCompleted(PhoneAuthCredential p0)
            {
                // This callback will be invoked in two situations:
                // 1 - Instant verification. In some cases the phone number can be instantly
                //     verified without needing to send or enter a verification code.
                // 2 - Auto-retrieval. On some devices Google Play services can automatically
                //     detect the incoming verification SMS and perform verification without
                //     user action.
                Log.Debug(TAG, "onVerificationCompleted:$credential");
                // [START_EXCLUDE silent]
                verificationInProgress = false;
                // [END_EXCLUDE]

                // [START_EXCLUDE silent]
                // Update the UI and attempt sign in with the phone credential
                onVerificationCompleted?.Invoke(p0);
                // [END_EXCLUDE]
            }
Example #19
0
            public async override void OnVerificationCompleted(PhoneAuthCredential credential)
            {
                // This callback will be invoked in two situations:
                // 1 - Instant verification. In some cases the phone number can be instantly
                //     verified without needing to send or enter a verification code.
                // 2 - Auto-retrieval. On some devices Google Play services can automatically
                //     detect the incoming verification SMS and perform verification without
                //     user action.

                if (credential != null)
                {
                    var user = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

                    if (user.User.Uid != null)
                    {
                        UpdateUser(user.User.Uid);
                    }
                }
            }
        public void OnVerificationCompleted(PhoneAuthCredential credential)
        {
            var smsCode = credential.SmsCode;

            _textInputEditText1.Focusable = false;
            _textInputEditText2.Focusable = false;
            _textInputEditText3.Focusable = false;
            _textInputEditText4.Focusable = false;
            _textInputEditText5.Focusable = false;
            _textInputEditText6.Focusable = false;

            _textInputEditText1.Text = smsCode[0].ToString();
            _textInputEditText2.Text = smsCode[1].ToString();
            _textInputEditText3.Text = smsCode[2].ToString();
            _textInputEditText4.Text = smsCode[3].ToString();
            _textInputEditText5.Text = smsCode[4].ToString();
            _textInputEditText6.Text = smsCode[5].ToString();

            DisplayVerificationSuccess();

            _auth.SignInWithCredential(credential)
            .AddOnCompleteListener(this);
        }
Example #21
0
        private async void VerifyButton_Click(object sender, EventArgs e)
        {
            string inputtedCode            = firstInput.Text + secondInput.Text + thirdInput.Text + fourthInput.Text + fifthInput.Text + sixthInput.Text;
            PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(VerificationId, inputtedCode);

            try
            {
                IAuthResult signinResult = await FirebaseAuth.SignInWithCredentialAsync(credential);

                if (signinResult != null && signinResult.User != null)
                {
                    Dialog.Dismiss();
                    MessagingCenter.Send(this, "PhoneAuthenticationDone");
                }
                else
                {
                    firstInput.Text = secondInput.Text = thirdInput.Text = fourthInput.Text = fifthInput.Text = sixthInput.Text = "0";
                }
            }
            catch (System.Exception)
            {
                firstInput.Text = secondInput.Text = thirdInput.Text = fourthInput.Text = fifthInput.Text = sixthInput.Text = "0";
            }
        }
 public PhoneAuthCompletedEventArgs(PhoneAuthCredential credential)
 {
     Credential = credential ?? throw new ArgumentNullException(nameof(credential));
 }
Example #23
0
 public PhoneAuthCredentialWrapper(PhoneAuthCredential phoneAuthCredential) : base(phoneAuthCredential)
 {
     _phoneAuthCredential = phoneAuthCredential;
 }
 public override void OnVerificationCompleted(PhoneAuthCredential credential)
 {
     Log.Debug("OnVerificationCompleted", "Worked");
     VerificationCompleted?.Invoke(this, new PhoneAuthCompletedEventArgs(credential));
 }
 private void SignInWithPhoneAuthCredential(PhoneAuthCredential credential)
 {
     Auth.SignInWithCredential(credential).AddOnCompleteListener(Activity, this);
 }
Example #26
0
 private void SignInWithPhoneAuthCredential(PhoneAuthCredential credential)
 {
     FirebaseAuth.Instance.SignInWithCredential(credential);
     ViewModel.IsOTPSent = false;
     ViewModel.ShowMainViewCommand.Execute();
 }
Example #27
0
 private void OnVerificationCompleted(PhoneAuthCredential authCredential)
 {
     SignInWithPhoneAuthCredential(authCredential);
 }
 public override void OnVerificationCompleted(PhoneAuthCredential p0) => _onVerificationCompleted?.Invoke(p0);
Example #29
0
 public override void OnVerificationCompleted(PhoneAuthCredential credential)
 {
     _onCompleted(credential);
 }
 public System.Threading.Tasks.Task UpdatePhoneNumberAsync(PhoneAuthCredential phoneAuthCredential)
 {
     return(UpdatePhoneNumber(phoneAuthCredential).AsAsync());
 }