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"); }); }
public IPhoneAuthCredential GetCredential(IAuth auth, string verificationId, string verificationCode) { var wrapper = (AuthWrapper)auth; var credential = PhoneAuthProvider.From((Auth)wrapper).GetCredential(verificationId, verificationCode); return(new PhoneAuthCredentialWrapper(credential)); }
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"); }); }
private async void SignIn_Click(object sender, EventArgs e) { string code = countryCode.Text.ToString().Trim(); string phone = phoneNumber.Text.ToString().Trim(); string pass_word = password.Text.ToString().Trim(); string verify = verifyCode.Text.ToString().Trim(); IAGConnectAuthCredential credential; if (TextUtils.IsEmpty(verify)) { credential = PhoneAuthProvider.CredentialWithPassword(code, phone, pass_word); } else { credential = PhoneAuthProvider.CredentialWithVerifyCode(code, phone, pass_word, verify); } try { AGConnectAuth connectAuth = AGConnectAuth.Instance; var signInResult = AGConnectAuth.Instance.SignInAsync(credential); ISignInResult result = await signInResult; if (signInResult.Status.Equals(System.Threading.Tasks.TaskStatus.RanToCompletion)) { Log.Debug(TAG, signInResult.Result.ToString()); resultConsole.Text = result.User.Uid; } } catch (Exception ex) { Log.Error(TAG, ex.Message); Toast.MakeText(this, "SignIn failed: " + ex.Message, ToastLength.Long).Show(); } }
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"); }); }
public void phoneVerify(string phoneNumber, string countryCodeStr, int registerOrreset) { try { settings = GenerateSettings(registerOrreset); HuaweiService.Task task = PhoneAuthProvider.requestVerifyCode(countryCodeStr, phoneNumber, settings); task.addOnSuccessListener(TaskExecutors.uiThread(), new HuaweiOnsuccessListener <VerifyCodeResult>((codeResult) => { UnityMainThread.instance.AddJob(() => { PanelController.popupinstance.ShowInfo("sms code send successfully!"); infoMessage.text = "sms code send successfully!"; }); })) .addOnFailureListener(TaskExecutors.uiThread(), new HuaweiOnFailureListener((e) => { UnityMainThread.instance.AddJob(() => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); infoMessage.text = e.toString(); }); })); }catch (System.Exception e) { Error error = new Error(); error.message = e.Message; PanelController.popupinstance.ShowError(error); } }
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; }
/// <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(); }
public void verify(int resetOrregister) { VerifyCodeSettings settings = new VerifyCodeSettings.Builder() .action(resetOrregister) .sendInterval(30) .locale(Locale.CHINA) .build(); if (isPhoneOrEmail) { task = EmailAuthProvider.requestVerifyCode(isModifyPassword?emailorPhone.text.Trim():newemailorPhoneorpassword.text.Trim(), settings); } else { task = PhoneAuthProvider.requestVerifyCode("+86", isModifyPassword?emailorPhone.text.Trim():newemailorPhoneorpassword.text.Trim(), settings); } task.addOnSuccessListener(TaskExecutors.uiThread(), new HuaweiOnsuccessListener <VerifyCodeResult>( (codeResult) => { showMessage.text = "code send successfully!"; PanelController.popupinstance.ShowInfo("code send successfully!"); })) .addOnFailureListener(TaskExecutors.uiThread(), new HuaweiOnFailureListener((e) => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); showMessage.text = e.toString(); })); }
private void PhoneImageViewBtn_Click(object sender, EventArgs e) { var phoneNumberDialogHandler = new EventHandler <DialogClickEventArgs>((alertDialog, clicked) => { var phoneNumberAlertDialog = alertDialog as AlertDialog; Button btnClicked = phoneNumberAlertDialog?.GetButton(clicked.Which); if (btnClicked?.Text != GetString(Resource.String.send_code)) { return; } var phoneNumber = phoneNumberAlertDialog?.FindViewById <EditText>(Resource.Id.phoneNumber); var mCallBacks = new PhoneAuthVerificationCallbacks(); mCallBacks.CodeSent += MCallBacks_CodeSent; mCallBacks.VerificationCompleted += MCallBacks_VerificationCompleted; PhoneAuthProvider.GetInstance(FirebaseAuth).VerifyPhoneNumber(phoneNumber?.Text, VERIFICATION_TIMEOUT, TimeUnit.Seconds, this, mCallBacks); }); AlertDialog phoneNumberAlert = new AlertDialog.Builder(this) .SetTitle(GetString(Resource.String.input_phone_number)) .SetPositiveButton(GetString(Resource.String.send_code), phoneNumberDialogHandler) .SetView(LayoutInflater.Inflate(Resource.Layout.PhoneNumberDialog, null)) .Show(); EditText phoneNumberInput = phoneNumberAlert.FindViewById <EditText>(Resource.Id.phoneNumber); //phoneNumberInput.AddTextChangedListener(new PhoneNumberFormattingTextWatcher("NG")); phoneNumberInput.AddTextChangedListener(new PhoneTextWatcher(phoneNumberInput)); }
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. }); }
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); }
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); }
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(); }); }
// 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"); }); }
private void OnEnable() { bool isEditor = false; #if UNITY_EDITOR isEditor = true; #endif if (isEditor) { FirebaseApp firebaseApp = FirebaseApp.Create( FirebaseApp.DefaultInstance.Options, "FIREBASE_EDITOR"); firebaseApp.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/"); FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { if (task.Result == DependencyStatus.Available) { _dbReference = FirebaseDatabase.GetInstance(firebaseApp).RootReference; _storage = FirebaseStorage.GetInstance(firebaseApp); _auth = FirebaseAuth.GetAuth(firebaseApp); _phoneProvider = PhoneAuthProvider.GetInstance(_auth); _functions = FirebaseFunctions.DefaultInstance; if (localServices.Value) { _functions.UseFunctionsEmulator("http://localhost:5001"); } // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } else { Debug.LogError("Could not resolve all Firebase dependencies: " + task.Result); Console.WriteLine("Could not resolve all Firebase dependencies: " + task.Result); // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } }); } else { FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/"); _dbReference = FirebaseDatabase.DefaultInstance.RootReference; _storage = FirebaseStorage.DefaultInstance; _functions = Firebase.Functions.FirebaseFunctions.DefaultInstance; _auth = FirebaseAuth.DefaultInstance; _phoneProvider = PhoneAuthProvider.GetInstance(_auth); // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } }
private void OnLoginButtonClick(object sender, EventArgs e) { // [START verify_with_code] var credential = PhoneAuthProvider.GetCredential(verificationId, ViewModel.OTP); // [END verify_with_code] SignInWithPhoneAuthCredential(credential); }
public void SubmitVerificationCode(string smsCode) { authType = AuthType.Phone; var credential = PhoneAuthProvider.GetCredential(VerificationId, smsCode); SignInWithCredential(credential); }
public void VerifyPhoneNumberWithCode(string verificationId, string code) { if (verificationId != null) { PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(verificationId, code); SignInWithPhoneAuthCredential(credential); } }
public void StartPhoneNumberVerification(string phoneNumber) { PhoneAuthProvider.GetInstance(Auth).VerifyPhoneNumber( phoneNumber, 60, TimeUnit.Seconds, Activity, MCallbacks); }
public void ResendVerificationCode(string phoneNumber, PhoneAuthProvider.ForceResendingToken token) { PhoneAuthProvider.GetInstance(Auth).VerifyPhoneNumber( phoneNumber, 60, TimeUnit.Seconds, Activity, MCallbacks, token); }
public void SendVerificationCode(string numeroCelular, PhoneValidationActivity Instance) { InitializeFirebase(); PhoneVerificationCallback phoneAuthCallbacks = new PhoneVerificationCallback(Instance); auth = GetFirebaseAuth(); PhoneAuthProvider.GetInstance(auth).VerifyPhoneNumber(numeroCelular, 30, TimeUnit.Seconds, Instance, phoneAuthCallbacks); }
private void SendVerificationCode() { var callbacks = new PhoneAuthCallBacks(this); PhoneAuthProvider.GetInstance(_auth).VerifyPhoneNumber( _phoneNo, 120, TimeUnit.Seconds, CrossCurrentActivity.Current.Activity, callbacks); }
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 void VerifyCode(string otpCode) { try { PhoneAuthCredential credential = PhoneAuthProvider.GetCredential(VerificationID, otpCode); InitializeCredentials(credential); } catch (IllegalArgumentException iae) { Log.Debug("illegalArgument on verificationID", iae.Message); } }
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)); }
private Task <PhoneNumberVerificationResult> VerifyPhoneNumberForTestingAsync(Firebase.Auth.FirebaseAuth auth, string phoneNumber, string verificationCode, TimeSpan timeout) { var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null"); var tcs = new TaskCompletionSource <PhoneNumberVerificationResult>(); var callbacks = new Callbacks(tcs); auth.FirebaseAuthSettings.SetAutoRetrievedSmsCodeForPhoneNumber(phoneNumber, verificationCode); PhoneAuthProvider.GetInstance(auth).VerifyPhoneNumber(phoneNumber, (long)timeout.TotalMilliseconds, TimeUnit.Milliseconds, activity, callbacks); return(tcs.Task); }
private void SignInUser(string phoneNo) { InitFirebaseAuth(); var callbacks = new PhoneAuthCallbacks(this); PhoneAuthProvider.GetInstance(_auth) .VerifyPhoneNumber( phoneNo, 2, TimeUnit.Minutes, this, callbacks); }
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 RequestVerifyCodeWithPhoneNumber() { VerifyCodeSettings verifyCodeSettings = new VerifyCodeSettings.Builder() .Action(VerifyCodeSettings.ACTION_REGISTER_LOGIN) .Locale(Locale.GetDefault()) .SendInterval(30).Build(); PhoneAuthProvider.RequestVerifyCode(PhoneCountryCode.text, PhoneNumber.text, verifyCodeSettings) .AddOnSuccessListener(verifyCodeResult => { verifyCodePhone.SetActive(true); }) .AddOnFailureListener(exception => { loggedInUser.text = exception.WrappedExceptionMessage; }); }