Access Claim values in controller in MVC 5

You need to set your Thread.CurrentPrincipal after login i.e. var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, result.UserFirstName)); claims.Add(new Claim(ClaimTypes.Sid, result.UserID.ToString())); var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); var claimsPrincipal = new ClaimsPrincipal(identity); // Set current principal Thread.CurrentPrincipal = claimsPrincipal; Then the following will retrieve the values. //Get the current claims principal var identity = (ClaimsPrincipal)Thread.CurrentPrincipal; // … Read more

MVC5 Claims version of the Authorize attribute

I ended up just writing a simple attribute to handle it. I couldn’t find anything in the framework right out of the box without a bunch of extra config. Listed below. public class ClaimsAuthorizeAttribute : AuthorizeAttribute { private string claimType; private string claimValue; public ClaimsAuthorizeAttribute(string type, string value) { this.claimType = type; this.claimValue = value; … Read more