public UserRepository(ICompanyRepository companyRepository, IOptions <AppSettings> appSettings,
                              ApiDBContext context) : base(context)

        {
            _companyRepository = companyRepository;
            _appSettings       = appSettings.Value;
        }
        private async Task attachAccountToContext(HttpContext context, ApiDBContext dataContext, 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 accountId = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value);

                // attach account to context on successful jwt validation
                context.Items["Account"] = await dataContext.Accounts.FindAsync(accountId);
            }
            catch
            {
                // do nothing if jwt validation fails

                // account is not attached to context so request won't have access to secure routes
            }
        }
Esempio n. 3
0
 public BasicAuthenticationHandler(
     IOptionsMonitor <AuthenticationSchemeOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     IUserService userService, ApiDBContext context)
     : base(options, logger, encoder, clock)
 {
     _userService = userService;
     _context     = context;
 }
Esempio n. 4
0
 public AccountService(
     ApiDBContext context,
     IMapper mapper,
     IOptions <AppSettings> appSettings,
     IEmailService emailService)
 {
     _context      = context;
     _mapper       = mapper;
     _appSettings  = appSettings.Value;
     _emailService = emailService;
 }
        public async Task Invoke(HttpContext context, ApiDBContext dataContext)
        {
            var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();

            if (token != null)
            {
                await attachAccountToContext(context, dataContext, token);
            }

            await _next(context);
        }
Esempio n. 6
0
 public CursoRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 7
0
 public StudentController()
 {
     this._db = new ApiDBContext();
 }
Esempio n. 8
0
 public CompanyRepository(ApiDBContext context,
                          ICompanyAuditRepository companyAuditRepository) : base(context)
 {
     _companyAuditRepository = companyAuditRepository;
 }
Esempio n. 9
0
 public AlunoRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 10
0
 public ClassController()
 {
     this._db = new ApiDBContext();
 }
Esempio n. 11
0
 public BillController(ApiDBContext context)
 {
     _db = context;
 }
Esempio n. 12
0
 public MantenimientoService(ApiDBContext _apiDBContext)
 {
     apiDBContext = _apiDBContext;
 }
Esempio n. 13
0
 public BsRolPermiso(ApiDBContext context)
 {
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }
Esempio n. 14
0
 public ApiService(ApiDBContext apiDBContext)
 {
     _apiDBContext = apiDBContext;
 }
 public LopsController()
 {
     this._db = new ApiDBContext();
 }
Esempio n. 16
0
 public PayScheduleController(ApiDBContext context)
 {
     _db = context;
 }
 public TasksContext(ApiDBContext context)
 {
     _context = context;
 }
Esempio n. 18
0
 public MeasurementService(ApiDBContext context)
 {
     _context = context;
 }
 public AddressRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 20
0
 public BankAccountRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 21
0
 public VehicleService(ApiDBContext context)
 {
     _context = context;
 }
Esempio n. 22
0
 public SqlRevisaoRepository(ApiDBContext context)
 {
     _context = context;
 }
Esempio n. 23
0
 public CompanyAuditRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 24
0
 public TurmaService(ApiDBContext context)
 {
     _context = context;
 }
 public TodoItemsController(ApiDBContext context)
 {
     _context = context;
 }
Esempio n. 26
0
 public ConsultasService(ApiDBContext _apiDBContext)
 {
     apiDBContext = _apiDBContext;
 }
 public UsuarioRepository(ApiDBContext context) : base(context)
 {
 }
Esempio n. 28
0
 public SqlFabricanteRepository(ApiDBContext context)
 {
     _context = context;
 }
 protected BaseRepository(ApiDBContext context)
 {
     _context = context;
 }
 public SinhViensController()
 {
     this._db = new ApiDBContext();
 }