/// <summary>
        /// Attempts to link the given phone number to the user, or provides a verification ID if unable.
        /// </summary>
        /// <param name="phoneNumber">The phone number the user is trying to link. Make sure to pass in a phone number with country code prefixed with plus sign ('+').</param>
        /// <returns>PhoneNumberSignInResult containing either a verification ID or an IAuthResultWrapper</returns>
        public IObservable <PhoneNumberSignInResult> LinkWithPhoneNumber(string phoneNumber)
        {
            return(Observable.Create <PhoneNumberSignInResult>(
                       async observer =>
            {
                string verificationId = null;

                try
                {
                    verificationId = await PhoneAuthProvider.DefaultInstance.VerifyPhoneNumberAsync(phoneNumber, null);
                }
                catch (NSErrorException ex)
                {
                    observer.OnError(GetFirebaseAuthException(ex));
                    return;
                }

                var result = new PhoneNumberSignInResult()
                {
                    VerificationId = verificationId
                };

                observer.OnNext(result);
                observer.OnCompleted();
            }));
        }
        /// <summary>
        /// Attempts to link the given phone number to the user, or provides a verification ID if unable.
        /// </summary>
        /// <param name="phoneNumber">The phone number the user is trying to link. Make sure to pass in a phone number with country code prefixed with plus sign ('+').</param>
        /// <returns>PhoneNumberSignInResult containing either a verification ID or an IAuthResultWrapper</returns>
        public IObservable <PhoneNumberSignInResult> LinkWithPhoneNumber(string phoneNumber)
        {
            var completionHandler = new PhoneNumberVerificationCallbackWrapper();

            PhoneAuthProvider.Instance.VerifyPhoneNumber(phoneNumber, 60, TimeUnit.Seconds, CrossCurrentActivity.Current.Activity, completionHandler);

            return(completionHandler.Verify()
                   .SelectMany(
                       verificationResult =>
            {
                if (verificationResult.AuthCredential != null)
                {
                    return LinkWithCredentialAsync(verificationResult.AuthCredential)
                    .ToObservable()
                    .Select(authResult => new PhoneNumberSignInResult()
                    {
                        AuthResult = authResult
                    });
                }
                else
                {
                    var signInResult = new PhoneNumberSignInResult()
                    {
                        VerificationId = verificationResult.VerificationId
                    };

                    return Observable.Return(signInResult);
                }
            }));
        }
Пример #3
0
 private IObservable <Unit> HandleResult(AuthAction authAction, PhoneNumberSignInResult result, IObservable <Unit> completionObservable)
 {
     if (result.AuthResult != null)
     {
         return(completionObservable);
     }
     else
     {
         return(ViewStackService.PushPage(new PhoneAuthVerificationCodeEntryViewModel(authAction, result.VerificationId, completionObservable)));
     }
 }