You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
693 B

  1. using Microsoft.AspNetCore.Http;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Security.Claims;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace FunctionalTests.Middleware
  8. {
  9. class AutoAuthorizeMiddleware
  10. {
  11. private readonly RequestDelegate _next;
  12. public AutoAuthorizeMiddleware(RequestDelegate rd)
  13. {
  14. _next = rd;
  15. }
  16. public async Task Invoke(HttpContext httpContext)
  17. {
  18. var identity = new ClaimsIdentity("cookies");
  19. identity.AddClaim(new Claim("sub", "1234"));
  20. httpContext.User.AddIdentity(identity);
  21. await _next.Invoke(httpContext);
  22. }
  23. }
  24. }