Пример #1
0
 public MailSender(IMailClient client,
                   ITokenDecoder tokenDecoder,
                   DataProtector dataProtector)
 {
     _client        = client;
     _tokenDecoder  = tokenDecoder;
     _dataProtector = dataProtector;
 }
 public ParkingLotController(IApiHelper apiHelper,
                             ITokenDecoder tokenDecoder,
                             DataProtector dataProtector)
 {
     _apiHelper     = apiHelper;
     _tokenDecoder  = tokenDecoder;
     _dataProtector = dataProtector;
 }
Пример #3
0
 public IdentityService(IUserIdentityService userIdentityService, ITokenDecoder tokenDecoder, IMapper mapper, IConfiguration configuration)
 {
     _userIdentityService = userIdentityService;
     _tokenDecoder        = tokenDecoder;
     _mapper        = mapper;
     _configuration = configuration;
     _discoveryUrl  = _configuration.GetSection("ApplicationUrl").Value;
     _client        = new HttpClient();
 }
Пример #4
0
 public UserController(IApiHelper apiHelper,
                       ITokenDecoder tokenDecoder,
                       DataProtector dataProtector,
                       MailSender mailSender)
 {
     _apiHelper     = apiHelper;
     _tokenDecoder  = tokenDecoder;
     _dataProtector = dataProtector;
     _mailSender    = mailSender;
 }
Пример #5
0
 public BookingController(IApiHelper apiHelper,
                          ITokenDecoder tokenDecoder,
                          IConfiguration configuration,
                          DataProtector dataProtector)
 {
     _apiHelper     = apiHelper;
     _tokenDecoder  = tokenDecoder;
     _dataProtector = dataProtector;
     _configuration = configuration;
 }
Пример #6
0
 protected BaseAuthHandler(
     IOptionsMonitor <TOptions> options,
     ILoggerFactory loggerFactory,
     UrlEncoder encoder,
     ISystemClock clock,
     UserManager <AppUser> userManager,
     ITokenDecoder tokenDecoder) : base(options, loggerFactory, encoder, clock)
 {
     _userManager  = userManager;
     _tokenDecoder = tokenDecoder;
 }
Пример #7
0
 public HeadersAuthHandler(UserManager <AppUser> userManager,
                           IOptionsMonitor <JwtAuthOptions> options,
                           ILoggerFactory loggerFactory,
                           UrlEncoder encoder,
                           ISystemClock clock,
                           ITokenDecoder tokenDecoder,
                           IHeadersSessionManager sessionManager,
                           ILogger <HeadersAuthHandler> logger) : base(options, loggerFactory, encoder, clock, userManager, tokenDecoder)
 {
     _sessionManager = sessionManager;
     _logger         = logger;
 }
Пример #8
0
        public static void JwtAuth(this IMiddlewareSupport middlewareSupport, ITokenDecoder <JwtToken> tokenDecoder,
                                   ILogger logger, Func <Request, bool> excludeFilter = null)
        {
            middlewareSupport.Use(async(context, next) =>
            {
                if (excludeFilter != null && excludeFilter(context.Request))
                {
                    await next(context);
                    return;
                }

                const string jwtHeaderPrefix = "Bearer ";

                if (!context.Request.Headers.ContainsKey("Authorization"))
                {
                    await Task.Run(() => context.Response.StatusCode = HttpStatusCode.Unauthorized);
                    return;
                }

                var authorizationHeader = context.Request.Headers["Authorization"].FirstOrDefault();
                if (authorizationHeader == null || !authorizationHeader.StartsWith(jwtHeaderPrefix))
                {
                    await Task.Run(() => context.Response.StatusCode = HttpStatusCode.Unauthorized);
                    return;
                }

                var token = authorizationHeader.Substring(jwtHeaderPrefix.Length);

                try
                {
                    var payload = tokenDecoder.DecodeToken(token);

                    var tokenExpires = ExpDateTimeConverter.ToDateTime(payload.exp);

                    if (tokenExpires <= DateTime.UtcNow)
                    {
                        await Task.Run(() => context.Response.StatusCode = HttpStatusCode.Unauthorized);
                        return;
                    }

                    context.Extensions.Register(new Session.Session(payload.username));
                }
                catch (Exception e)
                {
                    logger.LogError(e, $"Request {context.Request.Method} {context.Request.Url} unauthorized!");
                    await Task.Run(() => context.Response.StatusCode = HttpStatusCode.Unauthorized);
                    return;
                }

                await next(context);
            });
        }
Пример #9
0
 public CookieAuthHandler(
     UserManager <AppUser> userManager,
     IOptionsMonitor <CookieAuthOptions> options,
     ILoggerFactory loggerFactory,
     UrlEncoder encoder,
     ISystemClock clock,
     ITokenDecoder tokenDecoder,
     ICookieSessionManager jwtCookieSessionManager,
     ILogger <CookieAuthHandler> logger) : base(options, loggerFactory, encoder, clock, userManager, tokenDecoder)
 {
     _userManager             = userManager;
     _tokenDecoder            = tokenDecoder;
     _jwtCookieSessionManager = jwtCookieSessionManager;
     _logger = logger;
 }
Пример #10
0
 public AccountController(UserManager <AppUser> userManager,
                          IHttpContextAccessor httpContextAccessor,
                          ITokenDecoder tokenDecoder,
                          SignInManager <AppUser> signInManager,
                          ICookieSessionManager cookieSessionManager,
                          IHeadersSessionManager headersSessionManager,
                          ILogger <RefreshTokenProvider> logger,
                          UsersDbContext dbContext)
 {
     _userManager           = userManager;
     _httpContextAccessor   = httpContextAccessor;
     _tokenDecoder          = tokenDecoder;
     _signInManager         = signInManager;
     _cookieSessionManager  = cookieSessionManager;
     _headersSessionManager = headersSessionManager;
     _logger    = logger;
     _dbContext = dbContext;
 }
Пример #11
0
 public AuthorizationFilter(ITokenDecoder tokenDecoder, string role)
 {
     _tokenDecoder = tokenDecoder;
     _role         = role;
 }
Пример #12
0
 public NodeSerializer(IContainer cont, ITokenDecoder tokenValidator)
 {
     _container          = cont;
     this.tokenValidator = tokenValidator;
 }
Пример #13
0
 public ApiHelper(IConfiguration configuration, ITokenDecoder tokenDecoder)
 {
     _configuration = configuration;
     _tokenDecoder  = tokenDecoder;
 }