Ejemplo n.º 1
0
        public async Task <ValidationResultResponse> ValidateTwoFactorAuthenticationOTPAsync(TwoFactorAuthOTP twoFactorAuthOTP)
        {
            var response = new ValidationResultResponse()
            {
                Messages = new List <string>()
            };

            UserModel user = await userRepository.GetByIdAsync(twoFactorAuthOTP.UserId, true);

            if (user == null)
            {
                throw new ItemNotFoundException($"User with Id '{twoFactorAuthOTP.UserId}' not found while attempting to validate user OTP.");
            }

            // Confirm that this user has a valid authenticator registered
            if (!userManager.IsAuthenticatorTokenVerified(user))
            {
                response.Success = false;
                return(response);
            }

            twoFactorAuthOTP.OTP = twoFactorAuthOTP.OTP.Replace(" ", string.Empty).Replace("-", string.Empty);
            response.Success     = await userManager.VerifyTwoFactorTokenAsync(user, userManager.Options.Tokens.AuthenticatorTokenProvider, twoFactorAuthOTP.OTP);

            return(response);
        }
Ejemplo n.º 2
0
        public Task <ValidationResultResponse> TestAsync(LdapAuthenticationModeSubmit ldapAuthenticationModeSubmit)
        {
            var testResult     = new ValidationResultResponse();
            var resultMessages = new List <string>();

            var ldapModel = mapper.Map <LdapAuthenticationModeModel>(ldapAuthenticationModeSubmit);

            testResult.Success  = ldapConnectionService.TestLdapSettings(ldapModel, ref resultMessages);
            testResult.Messages = resultMessages;

            return(Task.FromResult(testResult));
        }
Ejemplo n.º 3
0
        public async Task ValidateTwoFactorAuthenticationOTPAsync_GivenUnverifiedTokenandFindableUser_ReturnsFailed()
        {
            var userRepository       = Substitute.For <IUserRepository>();
            var twoFactorAuthService = new TwoFactorAuthService(userRepository, customUserManagerFake);

            userRepository.GetByIdAsync(twoFactorAuthOTP.UserId, Arg.Any <bool>()).Returns(mockedUserModel);
            customUserManagerFake.SetAuthenticatorTokenVerified(false);
            customUserManagerFake.SetAuthenticatorOtpValid(true);

            ValidationResultResponse validationResultResponse = await twoFactorAuthService.ValidateTwoFactorAuthenticationOTPAsync(twoFactorAuthOTP);

            Assert.False(validationResultResponse.Success, "Giving unverfied token and findable user must return success false.");
        }