Exemple #1
0
        public async Task <Usuario> Authenticate(string username, string password)
        {
            var usuario = await _usuarioSqlServerRepository.Get(new Usuario { Username = username, Password = password });

            if (usuario == null)
            {
                return(null);
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(Settings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, usuario.Username),
                    new Claim("ThomasGreg", usuario.Role)
                }),
                Expires            = DateTime.UtcNow.AddDays(2),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            usuario.Token = tokenHandler.WriteToken(token);

            usuario.Password = null;

            return(usuario);
        }
        public async Task GetById(int id)
        {
            var usuarios = await _usuarioSqlServerRepository.Get(id);

            Assert.True(true);
        }