Exemplo n.º 1
0
 public void VerifyPhoneNumber(string phoneNumber)
 {
     _phoneProvider.VerifyPhoneNumber(phoneNumber, phoneVerificationTimeoutMS, null,
                                      verificationCompleted: (credential) => {
         Debug.Log("verificationCompleted");
         // Auto-sms-retrieval or instant validation has succeeded (Android only).
         // There is no need to input the verification code.
         // `credential` can be used instead of calling GetCredential().
         _userCredential = credential;
     },
                                      verificationFailed: (error) => {
         Debug.Log("verificationFailed");
         // The verification code was not sent.
         // `error` contains a human readable explanation of the problem.
     },
                                      codeSent: (id, token) => {
         Debug.Log("codeSent");
         // Verification code was successfully sent via SMS.
         // `id` contains the verification id that will need to passed in with
         // the code from the user when calling GetCredential().
         // `token` can be used if the user requests the code be sent again, to
         // tie the two requests together.
         _smsVerificationId = id;
         _smsResendToken    = token;
     },
                                      codeAutoRetrievalTimeOut: (id) =>
     {
         Debug.Log("codeAutoRetrievalTimeOut");
         _smsVerificationIdTimeoutRequest = id;
         ReSendPhoneNumberVerification(phoneNumber);
     }
                                      );
 }
Exemplo n.º 2
0
    public void NewSignIn()
    {
        auth = FirebaseAuth.DefaultInstance;
        string            phoneNumber        = "+79244225416";
        uint              phoneAuthTimeoutMs = 100000;
        PhoneAuthProvider provider           = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("Completed");
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("error");
        },
                                   codeSent: (id, token) =>
        {
            Debug.Log(id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Phone Auth, auto-verification timed out");
        });
    }
Exemplo n.º 3
0
    public void GetOTP()                                                                 //Function to send otp to the valid user mobile number
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;    //Firebase auth instance creation to start authorization activity


        uint phoneAuthTimeoutMs    = 10000;                                              //
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+91" + mobile.text, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("1");

            //OnVerifyOTP(credential);
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("Verification failed");
        },
                                   codeSent: (id, token) =>
        {
            phoneVerificationId = id;
            Debug.Log("+91" + mobile.text);
            Debug.Log("SMS Has been sent and the verification Id is  " + id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Code Retrieval Time out");
        });
    }
Exemplo n.º 4
0
        public void VerifyPhoneNumber(string phoneNumber)
        {
            _phoneNumber = phoneNumber;

            _provider = PhoneAuthProvider.GetInstance(Auth);
            _provider.VerifyPhoneNumber(_phoneNumber, PhoneAuthTimeout, null,
                                        verificationCompleted: (credential) =>
            {
                print("verification completed");
            },
                                        verificationFailed: (error) =>
            {
                print("verification failed");
            },
                                        codeSent: (id, token) =>
            {
                print("code sent");

                _verificationId = id;

                OnCodeSent?.Invoke();
            },
                                        codeAutoRetrievalTimeOut: (id) =>
            {
                print("code auto retrieval timed Out");
            });
        }
Exemplo n.º 5
0
        // Begin authentication with the phone number.
        protected void VerifyPhoneNumber()
        {
            PhoneAuthProvider phoneAuthProvider = PhoneAuthProvider.GetInstance(auth);

            phoneAuthProvider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                                cred =>
            {
                DebugLog("Phone Auth, auto-verification completed");
                if (signInAndFetchProfile)
                {
                    auth.SignInAndRetrieveDataWithCredentialAsync(cred).ContinueWith(
                        HandleSignInWithSignInResult);
                }
                else
                {
                    auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInWithUser);
                }
            },
                                                error => { DebugLog("Phone Auth, verification failed: " + error); },
                                                (id, token) =>
            {
                phoneAuthVerificationId = id;
                DebugLog("Phone Auth, code sent");
            },
                                                id => { DebugLog("Phone Auth, auto-verification timed out"); });
        }
Exemplo n.º 6
0
 public static void Register(string phoneNumber, UnityAction <RequestData> onRegister = null)
 {
     provider = PhoneAuthProvider.GetInstance(auth);
     provider.VerifyPhoneNumber(phoneNumber, 1000, null, OnVerificationCompleted,
                                OnVerificationFailed, OnCodeSent, OnCodeAutoRetrievalTimeout);
     _onRegister = onRegister;
 }
Exemplo n.º 7
0
    void GetOTP()
    {
        Debug.Log("Getting OTP");
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+917907136126", phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
        },
                                   verificationFailed: (error) =>
        {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
        },
                                   codeSent: (id, token) =>
        {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
        });
    }
        private Task <PhoneNumberVerificationResult> VerifyPhoneNumberAsync(Firebase.Auth.FirebaseAuth auth, IPhoneMultiFactorInfo phoneMultiFactorInfo, IMultiFactorSession multiFactorSession, TimeSpan timeout, bool?requiresSmsValidation = null)
        {
            var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null");

            var tcs       = new TaskCompletionSource <PhoneNumberVerificationResult>();
            var callbacks = new Callbacks(tcs);

            var builder = PhoneAuthOptions.NewBuilder(auth)
                          .SetActivity(activity)
                          .SetCallbacks(callbacks)
                          .SetMultiFactorHint(phoneMultiFactorInfo.ToNative())
                          .SetMultiFactorSession(multiFactorSession.ToNative())
                          .SetTimeout(new Java.Lang.Long((long)timeout.TotalMilliseconds), TimeUnit.Milliseconds);

            if (requiresSmsValidation.HasValue)
            {
                builder.RequireSmsValidation(requiresSmsValidation.Value);
            }

            auth.FirebaseAuthSettings.SetAutoRetrievedSmsCodeForPhoneNumber(null, null);

            PhoneAuthProvider.VerifyPhoneNumber(builder.Build());

            return(tcs.Task);
        }
Exemplo n.º 9
0
        public Task VerifyPhoneNumberAsync(Activity activity, string phoneNumber)
        {
            var callbacks = new PhoneVerificationStateChangeCallbacks(onCodeSent: x => _verificationId = x.VerificationId);
            var options   = PhoneAuthOptions
                            .NewBuilder()
                            .SetPhoneNumber(phoneNumber)
                            .SetTimeout(new Long(60), TimeUnit.Seconds)
                            .SetActivity(activity)
                            .SetCallbacks(callbacks)
                            .Build();

            PhoneAuthProvider.VerifyPhoneNumber(options);
            return(Task.CompletedTask);
        }
        public void StartVerification(string phoneNumber)
        {
            authType = AuthType.Phone;

            var options = new PhoneAuthOptions
                          .Builder(FirebaseAuth.Instance)
                          .SetPhoneNumber(phoneNumber)
                          .SetTimeout(Long.ValueOf(60), TimeUnit.Seconds)
                          .SetCallbacks(phoneCallback)
                          .SetActivity(Xamarin.Essentials.Platform.CurrentActivity)
                          .Build();

            PhoneAuthProvider.VerifyPhoneNumber(options);
            SetVerificationStatus(VerificationStatus.Initialized);
        }
        public void ResendVerificationCode(string phoneNumber)
        {
            authType = AuthType.Phone;

            var options = new PhoneAuthOptions
                          .Builder(FirebaseAuth.Instance)
                          .SetPhoneNumber(phoneNumber)
                          .SetTimeout(Long.ValueOf(60), TimeUnit.Seconds)
                          .SetCallbacks(phoneCallback)
                          .SetActivity(Xamarin.Essentials.Platform.CurrentActivity);

            if (ResendToken != null)
            {
                options.SetForceResendingToken(ResendToken);
            }

            PhoneAuthProvider.VerifyPhoneNumber(options.Build());
            SetVerificationStatus(VerificationStatus.Initialized);
        }
Exemplo n.º 12
0
    public void SignInGetPhoneOTP(string mobileNumber)
    {
        string phoneNumber        = "+91" + mobileNumber;
        uint   phoneAuthTimeoutMs = 120000;

        provider = PhoneAuthProvider.GetInstance(auth);
        Debug.Log(phoneNumber + ".....Phone number");
        AppHandler._instance._myData._mobileNumber = mobileNumber;
        provider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            Debug.Log(".....auto verify");
            OnSuccessLogin();
        },
                                   verificationFailed: (error) =>
        {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            Debug.Log(".....failed because ..." + error);
        },
                                   codeSent: (id, token) =>
        {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            Debug.Log("inside codesent");
            PlayerPrefs.SetString("verifyid", id);
            //				PlayerPrefs.SetString("verifytoken",token);
            _OTPautoVerifyFail?.Invoke();
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            Debug.Log("inside timeout");
        });
    }
Exemplo n.º 13
0
    public void PhoneGetVerificationCode_Click()
    {
        provider = PhoneAuthProvider.GetInstance(auth);
        WriteLog("Verify Phone Number" + txtPhoneNumber.text);

        txtBtnGetCode.text = "Resend Verification Code";

        provider.VerifyPhoneNumber(txtPhoneNumber.text, 60, null,         //phoneAuthTimeoutMs = 60
                                   verificationCompleted: (credential) => {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            WriteLog("Auto-sms-retrieval or instant validation has succeeded (Android only).");

            OnVerifyCode(credential);
        },
                                   verificationFailed: (error) => {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            WriteLog("The verification code was not sent.");
            WriteLog(error.ToString());
        },
                                   codeSent: (id, token) => {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            WriteLog("Verification code was successfully sent via SMS.");
            WriteLog("Id: " + id);
            WriteLog("Token: " + token);
            phoneId = id;
        },
                                   codeAutoRetrievalTimeOut: (id) => {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            WriteLog("Auto-sms-retrieval has timed out");
            WriteLog("Id: " + id);
        });
    }
Exemplo n.º 14
0
    public void GetOTP()                                                                 //Function to send otp to the valid user mobile number
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;    //Firebase auth instance creation to start authorization activity


        uint phoneAuthTimeoutMs    = 30000;                                              //
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+91" + phonenumber.text, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("1");

            //OnVerifyOTP(credential);
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("Verification failed");
        },
                                   codeSent: (id, token) =>
        {
            phoneVerificationId = id;
            Debug.Log("+91" + phonenumber.text);
            Debug.Log("SMS Has been sent and the verification Id is  " + id);
            runOTPTimer = true;
            resendOTPText.SetActive(false);
            resendOTPButton.SetActive(false);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            //this is callback function and will be called after otp entry time is over.
            //enable resend otp button here
            resendOTPText.SetActive(true);
            resendOTPButton.SetActive(true);
            Debug.Log("Code Retrieval Time out");
        });
    }
Exemplo n.º 15
0
    public void NewRegister()
    {
        if (tremsOfUseToggle.GetComponentInChildren <Toggle>().isOn&& labaRulesToggle.GetComponentInChildren <Toggle>().isOn)
        {
            string number = Verificator.IsValidPhoneNumber(phone_register.text);
            if (number == null)
            {
                Debug.Log("Неверно введен номер телефона");
                return;
            }
            if (!TestEmail.IsEmail(email_register.text))
            {
                Debug.Log("Неверно введен Email");
                return;
            }
            if (password_register.text.Trim().Length < 6)
            {
                Debug.Log("Пароль должен быть больше 6-ти символов");
                return;
            }
            if (name_register.text.Trim().Length < 2)
            {
                Debug.Log("Введите Имя");
                return;
            }
            if (lastName_register.text.Trim().Length < 1)
            {
                Debug.Log("Введите Фамилию");
                return;
            }
            if (patronymic_register.text.Trim().Length < 2)
            {
                Debug.Log("Введите Отчество");
                return;
            }


            Email        = email_register.text;
            Password     = password_register.text;
            Phone_Number = number;
            Name         = name_register.text;
            LastName     = lastName_register.text;
            Patronymic   = patronymic_register.text;
            Birthday     = "" + birthday_register[0].options[birthday_register[0].value].text + "/"
                           + birthday_register[1].options[birthday_register[1].value].text + "/"
                           + birthday_register[2].options[birthday_register[2].value].text;
            gameManager.ShowLoading(true);

            uint phoneAuthTimeoutMs = 60 * 1000;
            Provider = PhoneAuthProvider.GetInstance(Auth);
            Provider.VerifyPhoneNumber(Phone_Number, phoneAuthTimeoutMs, null,
                                       verificationCompleted: (credential) =>
            {
                Debug.Log("Completed");
                SignInAndUpdate(credential);
            },
                                       verificationFailed: (error) =>
            {
                Debug.Log("error");
                Debug.Log(error);
                gameManager.ShowLoading(false);
            },
                                       codeSent: (id, token) =>
            {
                Debug.Log(id);
                verificationId = id;
                gameManager.Panels[1].GetComponent <Animator>().Play("SSCR Fade-out");
                gameManager.Panels[2].GetComponent <Animator>().Play("SSCR Fade-in");
                gameManager.ShowLoading(false);
            },
                                       codeAutoRetrievalTimeOut: (id) =>
            {
                Debug.Log("Phone Auth, auto-verification timed out");
                gameManager.ShowLoading(false);
            });
        }
    }