public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (await _tokenManagerService.IsCurrentActiveToken()) { await next(context); return; } context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; }
public async Task Invoke(Microsoft.AspNetCore.Http.HttpContext context, IUserService userService) { var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last(); if (await tokenManagerService.IsCurrentActiveToken()) { if (token != null) { attachUserToContext(context, userService, token); } await _next(context); } else { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; var result = System.Text.Json.JsonSerializer.Serialize(new AppDomainResult() { ResultCode = context.Response.StatusCode, Success = false }); await context.Response.WriteAsync(result); } }