public IActionResult Authenticate([FromBody] Usuario userDto)
        {
            negocioAutorizacion = new NegocioAutorizacion();
            var user = negocioAutorizacion.Authenticate(userDto.Username, userDto.Password);

            if (user == null)
            {
                return(Unauthorized());
            }
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_Iconfiguration.GetSection("AppSettings").GetSection("Secret").Value);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.Id.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            return(Ok(new
            {
                Id = user.Id,
                Username = user.Username,
                Token = tokenString,
                rolId = user.rolId
            }));
        }
 public AuthorizationController(IConfiguration iconfiguration)
 {
     negocioAutorizacion = new NegocioAutorizacion();
     _Iconfiguration     = iconfiguration;
 }