Guest User

Untitled

a guest
Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public class AuthorisationAttribute : TypeFilterAttribute
  2. {
  3. public AuthorisationAttribute() : base(typeof(AuthorisationFilter))
  4. {
  5. Arguments = new object[] { new Claim(ClaimTypes.UserData, "will be my user data") };
  6. }
  7. }
  8. public class AuthorisationFilter : IAuthorizationFilter
  9. {
  10. readonly HttpContext _httpContext;
  11. public AuthorisationFilter(HttpContext httpContext)
  12. {
  13. _httpContext = httpContext;
  14. }
  15.  
  16. public void OnAuthorization(AuthorizationFilterContext context)
  17. {
  18. var authorisationCookie = context.HttpContext.Request.Headers.Where(t => t.Key == "auth").FirstOrDefault();
  19.  
  20. var temp = new JwtSecurityTokenHandler();
  21. var unencryptedToken = temp.ReadToken(authorisationCookie.Value) as JwtSecurityToken;
  22.  
  23. var session = _httpContext.Session;
  24. //MORE TO DO HERE YET! Just want to test getting called when expected.
  25. return;
  26. }
  27. }
  28.  
  29. public class HomeController : Controller
  30. {
  31. [Authorisation(),HttpGet]
  32. public IActionResult Index()
  33. {
  34. return View("~/Views/Home/Index.cshtml");
  35. }
  36. }
  37.  
  38. services.AddHttpContextAccessor();
  39.  
  40. public AuthorisationFilter(IHttpContextAccessor httpContextAccessor)
  41. {
  42. _httpContextAccessor = httpContextAccessor;
  43. }
  44.  
  45. context.HttpContext
Add Comment
Please, Sign In to add comment