private async Task AttachAccountToContext(HttpContext context, ApplicationDataContext dataContext) { context.Response.ContentType = MediaTypeNames.Application.Json; var accountId = context.AccountID(_jwtSettings); var account = await dataContext.Accounts.FindAsync(accountId); if (account == null) { throw new UnauthorizedAccessException("Unauthorized"); } else { context.Items["Account"] = account; await _next.Invoke(context); } }