Example #1
0
        public async Task<IActionResult> Login([FromBody]AuthSignInModel model)
        {
            JWTTokenStatusResult result = await _authorizationService.GenerateTokenAsync(model);
            if (!result.IsAuthorized) { return NotFound(); }

            return Ok(result);
        }
Example #2
0
        public async override Task <bool> VerifyUserAsync(AuthSignInModel model)
        {
            AppUser user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                return(false);
            }

            SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

            return(result.Succeeded);
        }
Example #3
0
        public override async Task <IEnumerable <Claim> > GetUserClaimsAsync(AuthSignInModel model)
        {
            AppUser user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                return(new List <Claim> {
                });
            }

            return(new List <Claim>()
            {
                new Claim(ClaimTypes.Name, user.UserName.ToString()),
                new Claim(ClaimTypes.Role, user.Role)
            });
        }
        public async Task <JWTTokenStatusResult> GenerateTokenAsync(AuthSignInModel model)
        {
            Boolean status = await VerifyUserAsync(model);

            if (!status)
            {
                return(new JWTTokenStatusResult()
                {
                    Token = null, IsAuthorized = false
                });
            }

            IEnumerable <Claim> claims = await GetUserClaimsAsync(model);

            JwtSecurityToken token = _tokenFactory.CreateToken(model.Email.ToString(), claims);

            return(new JWTTokenStatusResult()
            {
                Token = new JwtSecurityTokenHandler().WriteToken(token),
                IsAuthorized = true,
                Features = claims.Select(x => x.Value)
            });
        }
Example #5
0
        public override async Task <IEnumerable <Claim> > GetUserClaimsAsync(AuthSignInModel model)
        {
            AppRole userRole = _context.AppUsers.Include(u => u.Role)
                               .Where(x => x.Email == model.Email)
                               .FirstOrDefault()?.Role;

            if (userRole == null || !userRole.IsActive)
            {
                return(new List <Claim>());
            }

            List <AppFeature> features = _context.AppRoleFeatures
                                         .Include(f => f.AppFeature)
                                         .Where(f => f.AppRoleId == userRole.Id)
                                         .Select(f => f.AppFeature)
                                         .ToList();

            if (features.Select(f => f.Name).Contains(EnumsExtensions.GetDescription(AppFeatures.FullAccess)))
            {
                features = _context.AppFeatures.ToList();
            }

            return(_policyService.TransformFeaturesToClaims(features));
        }
Example #6
0
        public async Task <JWTTokenStatusResult> GenerateTokenAsync(AuthSignInModel model)
        {
            bool status = await VerifyUserAsync(model);

            if (!status)
            {
                return(new JWTTokenStatusResult()
                {
                    Token = null, IsAuthorized = false
                });
            }

            IEnumerable <Claim> claims = await GetUserClaimsAsync(model);

            JwtSecurityToken token = _tokenFactory.CreateToken(model.UserName.ToString(), claims);
            UserAuthInfo     info  = await GetUserInfoAsync(model.UserName);

            return(new JWTTokenStatusResult()
            {
                Token = new JwtSecurityTokenHandler().WriteToken(token),
                IsAuthorized = true,
                UserInfo = info,
            });
        }
 public abstract Task <Boolean> VerifyUserAsync(AuthSignInModel model);
 public abstract Task <IEnumerable <Claim> > GetUserClaimsAsync(AuthSignInModel model);