Ejemplo n.º 1
0
        public override void OnVerificationFailed(FirebaseException exception)
        {
            FirebaseAuthService.FirebaseExceptionTypeToEnumDict.TryGetValue(exception.GetType(), out FirebaseAuthExceptionType exceptionType);
            var customException = new FirebaseAuthException(exception.Message, exception, exceptionType);

            _subject.OnError(customException);
        }
Ejemplo n.º 2
0
        private string HandleFirebaseAuthException(FirebaseAuthException e)
        {
            if (e.Message.ContainsEnclosing('(', ')'))
            {
                return(e.Message.SubstringWithin('(', ')'));
            }

            return(Enum.GetName(typeof(AuthError), e.AuthErrorCode));
        }
Ejemplo n.º 3
0
        private async void HandleUserCollision(FirebaseAuthException ex)
        {
            pendingCredential = ex.UpdatedCredential;
            var providerIDs = await Auth.FetchSignInMethodsForEmailAsync(ex.Email !);

            var providers = providerIDs.Select(id => AuthProviderFromFirebaseId(id));
            await AiForms.Dialogs.Dialog.Instance.ShowAsync(userCollisionSelectionView = new AuthProviderSelectionView(
                                                                ButtonViewModels.Where(x => providers.Contains(x.Provider)),
                                                                AuthProviderFromFirebaseId(pendingCredential !.Provider)), this);
        }
 private void CheckException(
     FirebaseAuthException exception,
     string prefix,
     AuthErrorCode errorCode = AuthErrorCode.InvalidSessionCookie)
 {
     Assert.Equal(ErrorCode.InvalidArgument, exception.ErrorCode);
     Assert.StartsWith(prefix, exception.Message);
     Assert.Equal(errorCode, exception.AuthErrorCode);
     Assert.Null(exception.InnerException);
     Assert.Null(exception.HttpResponse);
 }
Ejemplo n.º 5
0
 public static string GetErrorReason(FirebaseAuthException exception)
 {
     switch (exception.Reason.ToString())
     {
         case "InvalidEmailAddress":
             return "Invalid Email Address";
         case "WeakPassword":
             return "Weak Password: A should be at least 6 characters";
         case "WrongPassword":
             return "Wrong Password";
         default:
             var error = "An undefined error occured while attempting to sign in.";
             ServiceLocator.Current.GetInstance<ILoggerService>().LogException(exception, error);
             return error;
     }
 }
Ejemplo n.º 6
0
 public void Invalid_password_should_be_reflected_by_failure_reason()
 {
     using (FirebaseAuthProvider authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)))
     {
         try
         {
             authProvider.SignInWithEmailAndPasswordAsync(FirebaseEmail, "xx" + FirebasePassword).Wait();
             Assert.Fail("Sign-in should fail with invalid password.");
         }
         catch (Exception e)
         {
             FirebaseAuthException exception = (FirebaseAuthException)e.InnerException;
             exception.Reason.Should().Be(AuthErrorReason.WrongPassword);
         }
     }
 }
Ejemplo n.º 7
0
 public void Invalid_email_address_format_should_be_reflected_by_failure_reason()
 {
     using (FirebaseAuthProvider authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)))
     {
         try
         {
             authProvider.SignInWithEmailAndPasswordAsync("notanemailaddress", FirebasePassword).Wait();
             Assert.Fail("Sign-in should fail with invalid email.");
         }
         catch (Exception e)
         {
             FirebaseAuthException exception = (FirebaseAuthException)e.InnerException;
             exception.Reason.Should().Be(AuthErrorReason.InvalidEmailAddress);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts the firebase api auth call to a full text error message.
        /// </summary>
        /// <param name="e"></param>
        /// <returns>The full text error message.</returns>
        private string GetRigthErrorMessage(FirebaseAuthException e)
        {
            if (e.Message.Contains("EMAIL_NOT_FOUND") || e.Message.Contains("INVALID_PASSWORD") || e.Message.Contains("INVALID_EMAIL"))
            {
                return("Email or/and Password incorrect.");
            }
            else if (e.Message.Contains("EMAIL_EXISTS"))
            {
                return("There is already a user with this email address.");
            }
            else if (e.Message.Contains("WEAK_PASSWORD"))
            {
                return("The password should be at least 6 characters long.");
            }

            return(e.Message);
        }
Ejemplo n.º 9
0
        private void ThrowFirebaseAuthException(FirebaseAuthException ex, adduohelper.envelopes.RequestEnvelope <T> request)
        {
            var response = request.CreateResponse();

            if (ex.ErrorCode == FirebaseAdmin.ErrorCode.AlreadyExists)
            {
                response.Item.Email.Status = adduohelper.entries.STATUS.INVALID;
                response.Item.Email.Code   = adduohelper.entries.CODE.ALREADY;
                response.HttpStatusCode    = HttpStatusCode.Conflict;
            }
            else if (ex.ErrorCode == FirebaseAdmin.ErrorCode.NotFound)
            {
                response.HttpStatusCode = HttpStatusCode.NotFound;
            }

            Throw(response);
        }
        public static CustomException Adapt(FirebaseAuthException e)
        {
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            dynamic response     = jsonSerializer.Deserialize <dynamic>(e.ResponseData);
            string  errorMessage = response["error"]["message"];
            string  msg          = "";

            switch (errorMessage)
            {
            case "INVALID_EMAIL": { msg = ("Error while sending login request: " + "Invalid email!" + "Login error!"); break; }

            case "EMAIL_NOT_FOUND": { msg = ("Error while sending login request: " + "Email not found!" + "Login error!"); break; }

            case "INVALID_PASSWORD": { msg = ("Error while sending login request: " + "Invalid password!" + "Login error!"); break; }

            case "MISSING_PASSWORD": { msg = ("Error while sending login request: " + "Missing password!" + "Login error!"); break; }

            default: { msg = ("Error while sending login request: " + errorMessage + ", Login error!"); break; }
            }
            return(new CustomException(msg));
        }
Ejemplo n.º 11
0
        private async Task ResolveAsync(FirebaseAuthException firebaseAuthException)
        {
            if (firebaseAuthException.Resolver == null)
            {
                System.Diagnostics.Debug.WriteLine(firebaseAuthException);

                await _pageDialogService.DisplayAlertAsync("Failure", firebaseAuthException.Message, "OK");
            }
            else
            {
                try
                {
                    var result = await _multiFactorService.ResolveAsync(firebaseAuthException.Resolver);

                    await _pageDialogService.DisplayAlertAsync("Success", result.User.DisplayName, "OK");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);

                    await _pageDialogService.DisplayAlertAsync("Failure", ex.Message, "OK");
                }
            }
        }