Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AuthorisationAttribute : TypeFilterAttribute
- {
- public AuthorisationAttribute() : base(typeof(AuthorisationFilter))
- {
- Arguments = new object[] { new Claim(ClaimTypes.UserData, "will be my user data") };
- }
- }
- public class AuthorisationFilter : IAuthorizationFilter
- {
- readonly HttpContext _httpContext;
- public AuthorisationFilter(HttpContext httpContext)
- {
- _httpContext = httpContext;
- }
- public void OnAuthorization(AuthorizationFilterContext context)
- {
- var authorisationCookie = context.HttpContext.Request.Headers.Where(t => t.Key == "auth").FirstOrDefault();
- var temp = new JwtSecurityTokenHandler();
- var unencryptedToken = temp.ReadToken(authorisationCookie.Value) as JwtSecurityToken;
- var session = _httpContext.Session;
- //MORE TO DO HERE YET! Just want to test getting called when expected.
- return;
- }
- }
- public class HomeController : Controller
- {
- [Authorisation(),HttpGet]
- public IActionResult Index()
- {
- return View("~/Views/Home/Index.cshtml");
- }
- }
- services.AddHttpContextAccessor();
- public AuthorisationFilter(IHttpContextAccessor httpContextAccessor)
- {
- _httpContextAccessor = httpContextAccessor;
- }
- context.HttpContext
Add Comment
Please, Sign In to add comment