예제 #1
0
    public void SignInPhone()
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);
                OTPTimerText.text = "Otp entered is invalid";
                return;
            }

            Debug.Log("Phone Sign In successed.");
            Firebase.Auth.FirebaseUser newUser = task.Result;

            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);

            userUID = newUser.UserId;


            GetUserName();
        });
    }
예제 #2
0
        public async Task <bool> VerifyOTP(string verificationId, string otp)
        {
            var credential = PhoneAuthProvider.GetCredential(verificationId, otp);
            var res        = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

            return(res.User != null);
        }
        /// <summary>
        /// Attaches the given phone credentials to the user. This allows the user to sign in to this account in the future with credentials for such provider.
        /// </summary>
        /// <param name="verificationId">The verification ID obtained by calling VerifyPhoneNumber.</param>
        /// <param name="verificationCode">The 6 digit SMS-code sent to the user.</param>
        /// <returns>Updated current account</returns>
        public IObservable <IFirebaseAuthResult> LinkWithPhoneNumber(string verificationId, string verificationCode)
        {
            AuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, verificationCode);

            return(_user.LinkWithCredentialAsync(credential).ToObservable().Select(x => new FirebaseAuthResult(x)));
            //return LinkWithCredentialAsync(credential).ToObservable();
        }
예제 #4
0
    public static void Verify(string code, UnityAction <RequestData> onVerify = null)
    {
        _onVerify = onVerify;
        Credential credential = provider.GetCredential(_id, code);

        LoginUser(credential, true);
    }
        public void SubmitVerificationCode(string smsCode)
        {
            authType = AuthType.Phone;

            var credential = PhoneAuthProvider.GetCredential(VerificationId, smsCode);

            SignInWithCredential(credential);
        }
예제 #6
0
        private void OnLoginButtonClick(object sender, EventArgs e)
        {
            // [START verify_with_code]
            var credential = PhoneAuthProvider.GetCredential(verificationId, ViewModel.OTP);

            // [END verify_with_code]
            SignInWithPhoneAuthCredential(credential);
        }
예제 #7
0
    public void SubmitSMSCode()
    {
        verificationCode = phone_SMS_code.text;

        Credential credential = Provider.GetCredential(verificationId, verificationCode);

        SignInAndUpdate(credential);
    }
        public void VerifyPhoneNumberWithCode(string verificationId, string code)
        {
            if (verificationId != null)
            {
                PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, code);

                SignInWithPhoneAuthCredential(credential);
            }
        }
예제 #9
0
        private IEnumerator VerifyCodeAsync(string code, Action <bool, string> cb)
        {
            LoadingPanel.Instance.LoadingStart(ELoading.Load);

            _elapsedTime = 0;

            var credential = _provider.GetCredential(_verificationId, code);

            var task = Auth.SignInWithCredentialAsync(credential);

            yield return(new WaitWhile(() => IsTask(task.IsCompleted)));

            if (task.IsFaulted || task.IsCanceled)
            {
                cb(true, "The phone auth credential was created\nwith an empty SMS verification Code.");
                LoadingPanel.Instance.LoadingStop();
                yield return(null);
            }
            else
            {
                yield return(StartCoroutine(FirebaseCore.GetPlayer((error, model) =>
                {
                    if (error)
                    {
                        var newUser = task.Result;
                        var userName = "******";
                        var phoneNumber = newUser.PhoneNumber;
                        var photoUrl = "  ";

                        PlayerPrefs.SetString(PrefsKeys.Name, "  ");
                        PlayerPrefs.SetString(PrefsKeys.Phone, "  ");
                        PlayerPrefs.SetString(PrefsKeys.PhotoUrl, "  ");
                        PlayerPrefs.Save();

                        var user = new UserModel(userName, phoneNumber, photoUrl);
                        FirebaseCore.CreateNewUser(user, newUser.UserId);

                        cb(false, phoneNumber);
                        LoadingPanel.Instance.LoadingStop();
                    }
                    else
                    {
                        PlayerPrefs.SetString(PrefsKeys.Name, model.UserName);
                        PlayerPrefs.SetString(PrefsKeys.Phone, model.PhoneNumber);
                        PlayerPrefs.SetString(PrefsKeys.PhotoUrl, model.PhotoUrl);
                        PlayerPrefs.Save();

                        OnUserNode?.Invoke(model);

                        LoadingPanel.Instance.LoadingStop();
                    }
                })));
            }
        }
예제 #10
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
            });
        }
 public Task <bool> VerifyOtpCodeAsync(string code)
 {
     if (!string.IsNullOrWhiteSpace(_verificationId))
     {
         var credential = PhoneAuthProvider.GetCredential(_verificationId, code);
         var tcs        = new TaskCompletionSource <bool>();
         FirebaseAuth.Instance.SignInWithCredentialAsync(credential)
         .ContinueWith((task) => OnAuthCompleted(task, tcs));
         return(tcs.Task);
     }
     return(Task.FromResult(false));
 }
예제 #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);
     }
 }
예제 #13
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);
                }
            }));
        }
예제 #14
0
        // Sign in using phone number authentication using code input by the user.
        protected void VerifyReceivedPhoneCode()
        {
            PhoneAuthProvider phoneAuthProvider = PhoneAuthProvider.GetInstance(auth);
            // receivedCode should have been input by the user.
            Credential cred = phoneAuthProvider.GetCredential(phoneAuthVerificationId, receivedCode);

            if (signInAndFetchProfile)
            {
                auth.SignInAndRetrieveDataWithCredentialAsync(cred).ContinueWith(
                    HandleSignInWithSignInResult);
            }
            else
            {
                auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInWithUser);
            }
        }
예제 #15
0
 /// <summary>
 /// Sign into Firebase with phone no.
 /// </summary>
 /// <param name="callBack">Callback for PCL</param>
 /// <param name="verificationId">Verification ID used in the credential object</param>
 /// <param name="code">SMS code used in the credential object</param>
 public Task <FirebaseResponse> SignIn(IFirebaseServiceCallBack callBack, string verificationId, string code)
 {
     try
     {
         // Set callback
         FirebaseServiceCallBack = callBack;
         // Create credential object
         SignIn(PhoneAuthProvider.GetCredential(verificationId, code));
         // Return response
         return(new Task <FirebaseResponse>(() => new FirebaseResponse(true)));
     }
     catch (Exception mes)
     {
         // Return exception
         return(new Task <FirebaseResponse>(() => new FirebaseResponse(mes.Message)));
     }
 }
예제 #16
0
    public void PhoneSignup()                                                              // Registers user through phone number and links with the mail
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);

                return;
            }

            Debug.Log("Phone Sign In successed.");
            // PhoneLoginSuccess();

            otpPanel.SetActive(false);
        });
    }
예제 #17
0
    public void SignInPhone()
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);

                return;
            }

            Debug.Log("Phone Sign In successed.");
            // PhoneLoginSuccess();
            patientOtpPanel.SetActive(false);
            mainRegPanelPatient.SetActive(true);
        });
    }
예제 #18
0
        public override async void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
        {
            _tvStatus.Text = "Sms code received. Now linking...";
            var         credential = PhoneAuthProvider.GetCredential(verificationId, MainActivity.SmsCode);
            IAuthResult result     = null;

            try
            {
                result = await FirebaseAuth.Instance.CurrentUser.LinkWithCredentialAsync(credential);
            }
            catch (FirebaseAuthException ex)
            {
                _tvStatus.Text        = ex.Message;
                _btnLinkPhone.Enabled = true;
                return;
            }

            _tvStatus.Text                 = "Account link successful.";
            _btnLinkPhone.Visibility       = ViewStates.Gone;
            _btnSigninAnonymous.Visibility = ViewStates.Visible;
            _btnSigninAnonymous.Enabled    = true;
        }
예제 #19
0
    public void SignInWithPhoneOTP(string OTPrecieved)
    {
        Credential credential =
            provider.GetCredential(PlayerPrefs.GetString("verifyid"), OTPrecieved);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " +
                               task.Exception);
                return;
            }

            FirebaseUser newUser = task.Result;
            Debug.Log("User signed in successfully");
            // This should display the phone number.
            Debug.Log("Phone number: " + newUser.PhoneNumber);
            // The phone number providerID is 'phone'.
            Debug.Log("Phone provider ID: " + newUser.ProviderId);
            OnSuccessLogin();
        });
    }
예제 #20
0
        public async Task <FirebaseUser> AuthenticateUserWithSMSVerificationCode(string verificationCode)
        {
            var credential     = _phoneProvider.GetCredential(_smsVerificationId, verificationCode);
            var credentialTask = _auth.SignInWithCredentialAsync(credential);

            try
            {
                var user = await credentialTask;
                if (debug.Value)
                {
                    Debug.LogFormat("User signed in successfully: {0} ({1} {2} {3})",
                                    user.DisplayName, user.UserId, user.PhoneNumber, user.ProviderId);
                }

                return(user);
            }
            catch (Exception e)
            {
                if (credentialTask.IsCanceled)
                {
                    Debug.LogError("AuthenticateUserWithSMSVerificationCode was canceled.");
                    Console.WriteLine("AuthenticateUserWithSMSVerificationCode was canceled.");
                    return(null);
                }

                if (credentialTask.IsFaulted)
                {
                    Debug.LogError($"AuthenticateUserWithSMSVerificationCode encountered an error: {credentialTask.Exception}");
                    Console.WriteLine($"AuthenticateUserWithSMSVerificationCode encountered an error: {credentialTask.Exception}");
                    return(null);
                }

                Debug.LogError(e);
                Console.WriteLine(e);
                return(null);
            }
        }
예제 #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";
            }
        }
예제 #22
0
 public Task <PhoneAuthCredential> GetCredentialAsync(string verificationCode)
 {
     return(Task.FromResult(PhoneAuthProvider.GetCredential(_verificationId, verificationCode)));
 }
예제 #23
0
    public void PhoneVerifyCode_Click()
    {
        Credential credential = provider.GetCredential(phoneId, txtCodeNumber.text);

        OnVerifyCode(credential);
    }
예제 #24
0
        public IPhoneAuthCredential GetCredential(IAuth auth, string verificationId, string verificationCode)
        {
            var credential = PhoneAuthProvider.GetCredential(verificationId, verificationCode);

            return(new PhoneAuthCredentialWrapper(credential));
        }
예제 #25
0
        /// <summary>
        /// Signs in to Firebase with the given phone number credentials.
        /// </summary>
        /// <param name="verificationId"></param>
        /// <param name="verificationCode">The 6 digit SMS-code sent to the user.</param>
        /// <returns>User account</returns>
        public async Task <IFirebaseAuthResult> SignInWithPhoneNumberAsync(string verificationId, string verificationCode)
        {
            AuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, verificationCode);

            return(await SignInAsync(credential));
        }
        /// <inheritdoc/>
        public IObservable <Unit> SignInWithPhoneNumber(string verificationId, string verificationCode)
        {
            AuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, verificationCode);

            return(SignInAsync(credential).ToObservable().Select(_ => Unit.Default));
        }
        private void VerifySentCode(string verificationCode)
        {
            var credential = PhoneAuthProvider.GetCredential(_verificationId, verificationCode);

            OnVerificationCompleted(credential);
        }
 public Task UpdatePhoneNumberAsync(string verificationId, string smsCode)
 {
     return(_wrapped.UpdatePhoneNumberAsync(PhoneAuthProvider.GetCredential(verificationId, smsCode)));
 }