public async Task Invoke(HttpContext context, IJwtAuthorizeHandler authorizeHandler) { try { if (!context.Request.Path.Value.EndsWith("login")) { var sessionHeader = context.Request.Headers["authorization"].ToString(); if (string.IsNullOrEmpty(sessionHeader)) { context.Response.StatusCode = 401; throw new AuthenticationException(); } if (sessionHeader.StartsWith(JwtBearerDefaults.AuthenticationScheme)) { var token = sessionHeader.Substring(JwtBearerDefaults.AuthenticationScheme.Length + 1); if (authorizeHandler.TokenExpired(token)) //TODO while token expired time is less than 1 min, refresh token { context.Response.StatusCode = 401; throw new AuthenticationException("Token expired"); } } await _next(context); } else { await _next(context); } } catch (Exception exception) { await HandleErrorAsync(context, exception); } }
public AuthController(IGate gate, IJwtAuthorizeHandler authorizeHandler) { _gate = gate; _authorizeHandler = authorizeHandler; }
public AuthController(IJwtAuthorizeHandler authorizeHandler) { _authorizeHandler = authorizeHandler; }