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