private async Task <object> GenerateJwtToken(string email, IdentityUser user)
        {
            var claims = new List <Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, email),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(ClaimTypes.NameIdentifier, user.Id)
            };

            var key     = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
            var creds   = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var expires = DateTime.Now.AddDays(Convert.ToDouble(_configuration["JwtExpireDays"]));

            var token = new JwtSecurityToken(
                _configuration["JwtIssuer"],
                _configuration["JwtIssuer"],
                claims,
                expires: expires,
                signingCredentials: creds
                );

            DtoLoginResponse response = new DtoLoginResponse()
            {
                token = new JwtSecurityTokenHandler().WriteToken(token)
            };

            return(response);
        }
        /// <summary>
        /// Valida el usuario en la base de datos
        /// </summary>
        /// <param name="pId">Numero de ID del producto registrada que se eliminara</param>
        /// <returns>Retorna TRUE si la eliminacion tuvo exito.</returns>
        public DtoLoginResponse Validar(DtoLoginRequest pEntidad)
        {
            DtoLoginResponse Dto = null;

            using (var db = new BD_SistemaVentaContext())
            {
                var response = db.Usuario.Where(x => x.UsuarioName == pEntidad.Usuario &&
                                                x.Password == pEntidad.Password &&
                                                x.Estado == 1)
                               .Select(x => new
                {
                    Id      = x.Id,
                    Usuario = x.UsuarioName,
                    Rol     = db.Parametros.Where(p => Convert.ToInt32(p.Valor1) == x.RoId && p.NroGrupo == 1).FirstOrDefault().Nombre,
                    Status  = x.Status == 1 ? "Activo" : "Inactivo",
                    Email   = x.Email
                }).ToList()

                               .Select(x => new DtoLoginResponse()
                {
                    Id      = x.Id,
                    Usuario = x.Usuario,
                    Rol     = x.Rol,
                    Status  = x.Status,
                    Email   = x.Email
                }).SingleOrDefault();

                Dto = response;
            }
            return(Dto);
        }
        /// <summary>
        /// Metodo que autentica el usuario.
        /// </summary>
        /// <param name="pEntidad">Entidad que contiene los datos</param>
        /// <returns>DtoLoginResponse</returns>
        public DtoLoginResponse Login(DtoLoginRequest pEntidad)
        {
            var urlClient      = string.Format("api/Usuarios/Validar");
            var restClient     = new RestService();
            var responseClient = restClient.PostAsync <RespuestaLogin <DtoLoginResponse> >(urlClient, pEntidad);

            DtoLoginResponse data = null;

            if (responseClient.Count != 0)
            {
                data = new DtoLoginResponse()
                {
                    Id      = responseClient.Dto.Id,
                    Usuario = responseClient.Dto.Usuario,
                    Rol     = responseClient.Dto.Rol,
                    Status  = responseClient.Dto.Status,
                    Email   = responseClient.Dto.Email,
                    Count   = responseClient.Count == 0 ? 0 : 1
                };
            }
            return(data);
        }