Exemple #1
0
        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
            }
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public ObjetivosController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #4
0
 public AspirantController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public TipoArticulosController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #6
0
 public UserController(MySQLDbContext dbContext, SecurityService security, EmailService mailService)
 {
     _dbContext = dbContext;
     _security  = security;
     _mail      = mailService;
 }
Exemple #7
0
 public MarcasController(MySQLDbContext context)
 {
     _context = context;
 }
 public MemoriasController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #9
0
 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);
 }
Exemple #11
0
 public ReportController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public LinpedsController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #13
0
 public EmployeeController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #14
0
 public LanguageController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #15
0
 public EquiposController(MySQLDbContext context)
 {
     _context = context;
 }
 public CamarasController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #17
0
 public TvController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #18
0
 public ProductosController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #19
0
 public StockController(MySQLDbContext context)
 {
     _context = context;
 }
 public ClientesController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #21
0
 public LocalidadesController(MySQLDbContext context)
 {
     _context = context;
 }
 public CapacitationLevelController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #23
0
 public PositionController(MySQLDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #24
0
 public EmpleadosController(MySQLDbContext context)
 {
     _context = context;
 }
 public Detalle_PedidoController(MySQLDbContext context)
 {
     _context = context;
 }
 public UsuariosController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #27
0
 public PedidosController(MySQLDbContext context)
 {
     _context = context;
 }
 public OficinasController(MySQLDbContext context)
 {
     _context = context;
 }
 public RolesController(MySQLDbContext context)
 {
     _context = context;
 }
Exemple #30
0
 public Gama_ProductoController(MySQLDbContext context)
 {
     _context = context;
 }