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.

33 lines
855 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. public const string IDENTITY_ID = "9e3163b9-1ae6-4652-9dc6-7898ab7b7a00";
  12. private readonly RequestDelegate _next;
  13. public AutoAuthorizeMiddleware(RequestDelegate rd)
  14. {
  15. _next = rd;
  16. }
  17. public async Task Invoke(HttpContext httpContext)
  18. {
  19. var identity = new ClaimsIdentity("cookies");
  20. identity.AddClaim(new Claim("sub", IDENTITY_ID));
  21. identity.AddClaim(new Claim("unique_name", IDENTITY_ID));
  22. httpContext.User.AddIdentity(identity);
  23. await _next.Invoke(httpContext);
  24. }
  25. }
  26. }