public void Setup()
        {
            _otpAlgorithm = MockRepository.GenerateMock<IOTPAlgorithm>();
            _movingFactorAlgorithm = MockRepository.GenerateMock<IMovingFactorAlgorithm>();
            _errorFactory = MockRepository.GenerateMock<IErrorFactory>();
            _otpConfiguration = new OTPConfiguration
            {
                OTPExpiryInSeconds = 31,
                NumberOfDigitsInOTP = 6,
                PrivateKey = "as9121jd623ms23h232k3"
            };
            _otpService = new OTPService(_otpAlgorithm, _movingFactorAlgorithm, _errorFactory, _otpConfiguration);
            _invalidRequestError = new OTPError
            {
                Code = "InvalidRequest",
                Description = "Please check your request and try again."
            };
            _errorFactory.Stub(factory => factory.GetInvalidRequestError()).Return(_invalidRequestError);

            _genericError = new OTPError
            {
                Code = "InternalError",
                Description = "Something went wrong, please try again later."
            };
            _errorFactory.Stub(factory => factory.GetErrorForException(null)).IgnoreArguments().Return(_genericError);
        }
        public void ShouldNotValidateOutsideExpiryLimit()
        {
            var otpConfiguration = new OTPConfiguration
            {
                OTPExpiryInSeconds  = 2,
                NumberOfDigitsInOTP = 6,
                PrivateKey          = "as9121jd623ms23h232k3"
            };

            _otpService = new OTPService(new HmacBasedOTPAlgorithm(),
                                         new ExpiryBasedMovingFactorAlgorithm(otpConfiguration), new ErrorFactory(),
                                         otpConfiguration);

            string userId = "2j32jk432m23482394jkddsd";
            var    generateOTPResponse = _otpService.GenerateOtp(new GenerateOTPRequest
            {
                UserId = userId
            });

            Assert.That(generateOTPResponse, Is.Not.Null);
            Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(generateOTPResponse.OTP, Is.Not.Empty);

            Thread.Sleep(5000);

            var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest
            {
                OTP    = generateOTPResponse.OTP,
                UserId = userId
            });

            Assert.That(validateOTPResponse, Is.Not.Null);
            Assert.That(validateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(validateOTPResponse.Success, Is.False);
        }
Beispiel #3
0
 public UserService(IOptions <AppSettings> appSettings,
                    IMapper mapper, IEmailService emailService,
                    IHttpContextAccessor httpContextAccessor,
                    IUtilityRepository utilityRepository,
                    UserManager <AppUser> userManager,
                    SignInManager <AppUser> signInManager,
                    AppDbContext context,
                    RoleManager <Role> roleManager,
                    IHostingEnvironment env,
                    IOTPService otpService,
                    IOTPAppService otpAppService,
                    IDocumentAppService documentAppService,
                    IStateService stateService)
 {
     _settings            = appSettings.Value;
     _userManager         = userManager;
     _signInManager       = signInManager;
     _mapper              = mapper;
     _utilityRepository   = utilityRepository;
     _httpContextAccessor = httpContextAccessor;
     _emailService        = emailService;
     _context             = context;
     _roleManager         = roleManager;
     _stateService        = stateService;
     _otpService          = otpService;
     _otpAppService       = otpAppService;
     _env = env;
     _documentAppService = documentAppService;
 }
        public GenerateModule(IOTPService otpService)
        {
            Get["/Generate"] = parameters => { return(View["Generate"]); };

            Post["/Generate"] = parameters =>
            {
                var generateOTPRequest  = this.Bind <GenerateOTPRequest>();
                var generateOTPResponse = otpService.GenerateOtp(generateOTPRequest);
                return(View["Generate", generateOTPResponse]);
            };
        }
        public GenerateModule(IOTPService otpService)
        {
            Get["/Generate"] = parameters => {return View["Generate"];
            };

            Post["/Generate"] = parameters =>
            {
                var generateOTPRequest = this.Bind<GenerateOTPRequest>();
                var generateOTPResponse = otpService.GenerateOtp(generateOTPRequest);
                return View["Generate", generateOTPResponse];
            };
        }
        public ValidateModule(IOTPService otpService)
        {
            Get["/Validate"] = parameters => {
                return(View["Validate"]);
            };

            Post["/Validate"] = parameters =>
            {
                var validateOTPRequest  = this.Bind <ValidateOTPRequest>();
                var validateOTPResponse = otpService.ValidateOtp(validateOTPRequest);
                return(View["Validate", validateOTPResponse]);
            };
        }
        public ValidateModule(IOTPService otpService)
        {
            Get["/Validate"] = parameters => {
                                                 return View["Validate"];
            };

            Post["/Validate"] = parameters =>
            {
                var validateOTPRequest = this.Bind<ValidateOTPRequest>();
                var validateOTPResponse = otpService.ValidateOtp(validateOTPRequest);
                return View["Validate", validateOTPResponse];
            };
        }
Beispiel #8
0
 public SubscriptionAppService(ISubscriptionService subscriptionService,
                               IMapper mapper,
                               IOTPService otpService,
                               IPlotService plotService,
                               IHttpContextAccessor httpContextAccessor,
                               UserManager <AppUser> userManager)
 {
     _subscriptionService = subscriptionService;
     _mapper = mapper;
     _httpContextAccessor = httpContextAccessor;
     _userManager         = userManager;
     _otpService          = otpService;
     _plotService         = plotService;
 }
Beispiel #9
0
        public void Setup()
        {
            _profile       = Substitute.For <IProfile>();
            _hash          = Substitute.For <IHash>();
            _otpService    = Substitute.For <IOTPService>();
            _failedCounter = Substitute.For <IFailedCounter>();
            _logger        = Substitute.For <ILogger>();
            _notification  = Substitute.For <INotification>();
            var authenticationService = new AuthenticationService(
                _hash, _otpService, _profile);
            var notificationDecorator  = new NotificationDecorator(authenticationService, _notification);
            var failedCounterDecorator = new FailedCounterDecorator(notificationDecorator, _failedCounter);

            _authentication = new LogFailedCountDecorator(failedCounterDecorator, _failedCounter, _logger);
        }
Beispiel #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="subscriberService"></param>
 /// <param name="mapper"></param>
 public SubscriberAppService(ISubscriberService subscriberService,
                             IMapper mapper, IHostingEnvironment env,
                             IOTPService otpService,
                             IUtilityRepository utilityRepository,
                             UserManager <AppUser> userManager,
                             IOptions <AppSettings> appSettings,
                             IPaymentService paymentService,
                             IUserService userService,
                             IRequestRepository requestRepository,
                             IEmailService emailService)
 {
     _subscriberService = subscriberService;
     _mapper            = mapper;
     _emailService      = emailService;
     _env               = env;
     _otpService        = otpService;
     _settings          = appSettings.Value;
     _userManager       = userManager;
     _utilityRepository = utilityRepository;
     _paymentService    = paymentService;
     _requestRepository = requestRepository;
     _userService       = userService;
 }
Beispiel #11
0
 public CustomerService(ICustomerRepository customerRepository,
                        IOTPRepository oTPRepository,
                        IPaymentRepository paymentRepository,
                        IPayoutRepository payoutRepository,
                        IRefundRepository refundRepository,
                        ICreditCardRepository creditCardRepository,
                        IMapper mapper,
                        IUnitOfWork unitOfWork,
                        IOTPService oTPService,
                        IOptions <CrediCardSetting> options,
                        ICustomerDeviceRepository customerDeviceRepository)
 {
     _customerRepository   = customerRepository;
     _paymentRepository    = paymentRepository;
     _payoutRepository     = payoutRepository;
     _refundRepository     = refundRepository;
     _creditCardRepository = creditCardRepository;
     _oTPRepository        = oTPRepository;
     _mapper     = mapper;
     _unitOfWork = unitOfWork;
     _oTPService = oTPService;
     SETTING     = options;
     _customerDeviceRepository = customerDeviceRepository;
 }
 public CustomerController(ICustomerService customerService, ISendGridService sendGridService, IOTPService oTPService)
 {
     _customerService = customerService;
     _sendGridService = sendGridService;
     _oTPService      = oTPService;
 }
Beispiel #13
0
 public OTPController(IOTPService otpService, OTPResultViewModelBuilder viewModelBuilder)
 {
     this._otpService       = otpService;
     this._viewModelBuilder = viewModelBuilder;
 }
Beispiel #14
0
 public AuthenticationService()
 {
     _hash       = new Sha256Adapter();
     _otpService = new OTPService();
     _profile    = new Profile();
 }
Beispiel #15
0
 public AuthenticationService(IHash hash, IOTPService otpService, IProfile profile)
 {
     _hash       = hash;
     _otpService = otpService;
     _profile    = profile;
 }
Beispiel #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="otpService"></param>
 /// <param name="userManager"></param>
 public OTPAppService(IOTPService otpService, UserManager <AppUser> userManager)
 {
     _otpService  = otpService;
     _userManager = userManager;
 }