private void AttachUserToContext(HttpContext context, MySQLDbContext dbContext, string token) { try { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); tokenHandler.ValidateToken(token, new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false, // Set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later) ClockSkew = TimeSpan.Zero }, out SecurityToken validatedToken); var jwtToken = (JwtSecurityToken)validatedToken; var userId = int.Parse(jwtToken.Claims.First(x => x.Type == "usuarioId").Value); // Attach user to context on successful jwt validation context.Items["User"] = dbContext.Usuarios.FirstOrDefault(x => x.UsuarioId == userId); } catch { // do nothing if jwt validation fails // user is not attached to context so request won't have access to secure routes } }
public async Task Invoke(HttpContext context, MySQLDbContext dbContext) { var token = context.Request.Headers["Authorization"].FirstOrDefault()? .Split(" ") .Last(); if (token != null) { AttachUserToContext(context, dbContext, token); } await _next(context); }
public ObjetivosController(MySQLDbContext context) { _context = context; }
public AspirantController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public TipoArticulosController(MySQLDbContext context) { _context = context; }
public UserController(MySQLDbContext dbContext, SecurityService security, EmailService mailService) { _dbContext = dbContext; _security = security; _mail = mailService; }
public MarcasController(MySQLDbContext context) { _context = context; }
public MemoriasController(MySQLDbContext context) { _context = context; }
public TicketsController(MySQLDbContext context) { _context = context; }
public MySQLBulkRepository(MySQLDbContext context) { _typedClient = new TypedClient <TEntity, MySqlConnection, TKey>(context.ConnectionString, SQLLanguageType.MySQL); _bulkClient = new MySQLBulkClient <TEntity>(context.ConnectionString); }
public ReportController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public LinpedsController(MySQLDbContext context) { _context = context; }
public EmployeeController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public LanguageController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public EquiposController(MySQLDbContext context) { _context = context; }
public CamarasController(MySQLDbContext context) { _context = context; }
public TvController(MySQLDbContext context) { _context = context; }
public ProductosController(MySQLDbContext context) { _context = context; }
public StockController(MySQLDbContext context) { _context = context; }
public ClientesController(MySQLDbContext context) { _context = context; }
public LocalidadesController(MySQLDbContext context) { _context = context; }
public CapacitationLevelController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public PositionController(MySQLDbContext dbContext) { _dbContext = dbContext; }
public EmpleadosController(MySQLDbContext context) { _context = context; }
public Detalle_PedidoController(MySQLDbContext context) { _context = context; }
public UsuariosController(MySQLDbContext context) { _context = context; }
public PedidosController(MySQLDbContext context) { _context = context; }
public OficinasController(MySQLDbContext context) { _context = context; }
public RolesController(MySQLDbContext context) { _context = context; }
public Gama_ProductoController(MySQLDbContext context) { _context = context; }