Esempio n. 1
0
        public override async Task AuthenticateLocalAsync(LocalAuthenticationContext ctx)
        {
            var username = ctx.UserName;
            var password = ctx.Password;
            var message  = ctx.SignInMessage;

            ctx.AuthenticateResult = null;

            IUserStoreService service = GetUserStoreService(message.ClientId);

            var user = service.GetUser(ctx.UserName, ctx.Password);

            if (user != null)
            {
                var result = await PostAuthenticateLocalAsync(user, message);

                if (result == null)
                {
                    var claims = GetUserClaims(user);
                    result = new AuthenticateResult(user.Id.ToString(), user.DisplayName, claims);
                }

                ctx.AuthenticateResult = result;
            }
            else
            {
                ctx.AuthenticateResult = new AuthenticateResult("User cannot be authenticated due to incorrect credentials");
            }
        }
Esempio n. 2
0
        public override async Task GetProfileDataAsync(ProfileDataRequestContext ctx)
        {
            var subject             = ctx.Subject;
            var requestedClaimTypes = ctx.RequestedClaimTypes;

            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            int userID = Convert.ToInt32(subject.GetSubjectId());

            IUserStoreService service = GetUserStoreService(ctx.Client.ClientId);

            var user = service.GetUserProfileData(userID);

            if (user == null)
            {
                throw new ArgumentException("Invalid subject identifier");
            }

            var claims = GetUserClaims(user);

            if (requestedClaimTypes != null && requestedClaimTypes.Any())
            {
                claims = claims.Where(x => requestedClaimTypes.Contains(x.Type));
            }

            ctx.IssuedClaims = claims;
        }
Esempio n. 3
0
        protected async Task <AuthenticateResult> PostAuthenticateLocalAsync(User user, SignInMessage message)
        {
            ClientScopeService clientScopeService = new ClientScopeService();

            bool isTwoFactorAuthentication = clientScopeService.IsTwoFactorAuthentication(message.ClientId);

            if (isTwoFactorAuthentication && (user.TwoFactorEmailAuthEnabled || user.TwoFactorSMSAuthEnabled))
            {
                IUserStoreService service = GetUserStoreService(message.ClientId);

                var result = service.GenerateAndSendOTP(user.Id);

                if (!result)
                {
                    return(new AuthenticateResult("Due to an error, OTP code could not be sent. Please try again. If this problem persists, please contact seystem administrator."));
                }

                var claims = GetUserClaims(user);
                return(new AuthenticateResult("~/custom/2fa?id=" + ctx.Request.Query.Get("id"), user.Subject, user.DisplayName, claims));
            }
            else
            {
                return(null);
            }
        }
 public UserController(UserManager <User> userManager, SignInManager <User> signInManager, ITokenService tokenService, IUserStoreService userStoreService)
 {
     _userManager      = userManager;
     _signInManager    = signInManager;
     _tokenService     = tokenService;
     _userStoreService = userStoreService;
 }
Esempio n. 5
0
        public async Task <bool> VerifyTwoFactorTokenAsync(string userId, string code, SignInMessage message)
        {
            IUserStoreService service = GetUserStoreService(message.ClientId);

            var result = service.VerifyOTP(Convert.ToInt32(userId), Convert.ToInt32(code));

            return(result);
        }
 public ManageUserStoreController(IUnitOfWork _unitofwork)
     : base(_unitofwork)
 {
     _store     = new StoreService(_unitofwork);
     _common    = new CommonService(_unitofwork);
     _UserStore = new UserStoreService(_unitofwork);
     _user      = new UserService(_unitofwork);
 }
Esempio n. 7
0
 public AccountController(IIdentityServerInteractionService identityServerInteractionService, IUserStoreService testUserStore, IEventService events, IHttpContextAccessor httpContextAccessor, IAuthenticationSchemeProvider schemeProvider, IClientStore clientStore, IResourceStore resourceStore, UserManager <IdentityUser> userManager)
 {
     _userManager = userManager;
     _identityServerInteractionService = identityServerInteractionService;
     _testUserStore       = testUserStore;
     _events              = events;
     _httpContextAccessor = httpContextAccessor;
     _schemeProvider      = schemeProvider;
     _clientStore         = clientStore;
     _resourceStore       = resourceStore;
 }
Esempio n. 8
0
 public AccountController(
     UserManager <IdentityUser> userManager,
     SignInManager <IdentityUser> signInManager,
     IConfiguration configuration,
     IUserStoreService userStoreService,
     ICoreApplicationService appService)
 {
     this.userManager   = userManager;
     this.signInManager = signInManager;
     this.configuration = configuration;
     this.appService    = appService;
 }
Esempio n. 9
0
 public UserClaimsPrincipal(UserManager <ApplicationUser> userManager,
                            RoleManager <ApplicationRole> roleManager, IOptions <IdentityOptions> optionsAccessor, IUserStoreService storeService)
 {
     if (userManager == null)
     {
         throw new ArgumentNullException(nameof(userManager));
     }
     if (optionsAccessor == null || optionsAccessor.Value == null)
     {
         throw new ArgumentNullException(nameof(optionsAccessor));
     }
     if (roleManager == null)
     {
         throw new ArgumentNullException(nameof(roleManager));
     }
     UserManager   = userManager;
     Options       = optionsAccessor.Value;
     RoleManager   = roleManager;
     _storeService = storeService;
 }
Esempio n. 10
0
        public UserManager(
            IUserStoreService store,
            IUnitOfWork uow,
            Lazy <Func <IIdentity> > identity, // For lazy loading -> Controller gets constructed before the HttpContext has been set by ASP.NET.
            IRoleManager roleManager,
            IDataProtectionProvider dataProtectionProvider,
            IIdentityMessageService smsService,
            IIdentityMessageService emailService)
            : base((IUserStore <User, string>)store)
        {
            _store                  = store;
            _uow                    = uow;
            _identity               = identity;
            _users                  = _uow.Set <User>();
            _roleManager            = roleManager;
            _dataProtectionProvider = dataProtectionProvider;
            this.SmsService         = smsService;
            this.EmailService       = emailService;

            createApplicationUserManager();
        }
Esempio n. 11
0
 public UserWriterService(IUserStoreService userStoreService)
 {
     _userStoreService = userStoreService;
 }
 public CoreApplicationService(IUserStoreService userStoreService, IRefTypeService refTypeService)
 {
     this.userStoreService = userStoreService;
     this.refTypeService   = refTypeService;
 }
Esempio n. 13
0
 public CustomProfileService(IUserStoreService userStoreServices)
 {
     _userStoreServices = userStoreServices;
 }
Esempio n. 14
0
        public UserService(
            IUserStoreService userStoreService,
            IUserTokenStorageService userTokenStorageService,
            IOptions <IdentityOptions> optionsAccessor,
            IPasswordHasher <User> passwordHasher,
            IEnumerable <IUserValidator <User> > userValidators,
            IEnumerable <IPasswordValidator <User> > passwordValidators,
            ILookupNormalizer keyNormalizer,
            ISecurityService securityService,
            IdentityErrorDescriber identityErrorDescriber,
            IServiceProvider serviceProvider,
            ILogger <UserService> logger,
            IHttpContextAccessor httpContextAccessor,
            IUnitOfWork unitOfWork,
            IEmailService emailService,
            IAntiForgeryCookieService antiForgeryCookieService,
            IOptionsSnapshot <SiteSettings> options,
            IUsedPasswordService usedPasswordService,
            IUserTokenFactoryService userTokenFactoryService,
            IMapper mapper)
            : base((IUserStore <User>)userStoreService, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, identityErrorDescriber, serviceProvider, logger)
        {
            _userStoreService = userStoreService;
            _userStoreService.CheckArgumentIsNull(nameof(_userStoreService));

            _userTokenStorageService = userTokenStorageService;
            _userTokenStorageService.CheckArgumentIsNull(nameof(_userTokenStorageService));

            _optionsAccessor = optionsAccessor;
            _optionsAccessor.CheckArgumentIsNull(nameof(_optionsAccessor));

            _passwordHasher = passwordHasher;
            _passwordHasher.CheckArgumentIsNull(nameof(_passwordHasher));

            _userValidators = userValidators;
            _userValidators.CheckArgumentIsNull(nameof(_userValidators));

            _passwordValidators = passwordValidators;
            _passwordValidators.CheckArgumentIsNull(nameof(_passwordValidators));

            _keyNormalizer = keyNormalizer;
            _keyNormalizer.CheckArgumentIsNull(nameof(_keyNormalizer));

            _securityService = securityService;
            _securityService.CheckArgumentIsNull(nameof(_securityService));

            _identityErrorDescriber = identityErrorDescriber;
            _identityErrorDescriber.CheckArgumentIsNull(nameof(_identityErrorDescriber));

            _serviceProvider = serviceProvider;
            _serviceProvider.CheckArgumentIsNull(nameof(_serviceProvider));

            _logger = logger;
            _logger.CheckArgumentIsNull(nameof(_logger));

            _stringEncryption = new StringEncryption();
            _stringEncryption.CheckArgumentIsNull(nameof(_stringEncryption));

            _httpContextAccessor = httpContextAccessor;
            _httpContextAccessor.CheckArgumentIsNull(nameof(_httpContextAccessor));

            _unitOfWork = unitOfWork;
            _unitOfWork.CheckArgumentIsNull(nameof(_unitOfWork));

            _usedPasswordService     = usedPasswordService;
            _userTokenFactoryService = userTokenFactoryService;
            _mapper = mapper;
            _usedPasswordService.CheckArgumentIsNull(nameof(_usedPasswordService));

            _antiForgeryCookieService = antiForgeryCookieService;
            _antiForgeryCookieService.CheckArgumentIsNull(nameof(_antiForgeryCookieService));

            _emailService = emailService;
            _emailService.CheckArgumentIsNull(nameof(_emailService));

            options.CheckArgumentIsNull(nameof(options));
            _options      = options;
            _smsTemplates = options.Value.SmsTemplates;

            _users = _unitOfWork.Set <User>();
            _roles = _unitOfWork.Set <Role>();
        }
Esempio n. 15
0
 public CustomPasswordOwnerUserServices(IUserStoreService userStoreServices)
 {
     _userStoreServices = userStoreServices;
 }
Esempio n. 16
0
 public UserClaimsPrincipal(IUserStoreService storeService)
 {
     _storeService = storeService;
 }
Esempio n. 17
0
 public CustomExtensionGrantUserServices(IUserStoreService userStoreServices)
 {
     _userStoreServices = userStoreServices;
 }
Esempio n. 18
0
 public UserWriterService(IUserStoreService userStoreService)
 {
     _userStoreService = userStoreService;
 }