// Create a list of claims var claimsList = new List(){ new Claim(ClaimTypes.Name, "John"), new Claim(ClaimTypes.Email, "[email protected]"), new Claim(ClaimTypes.Role, "Admin") }; // Create a ClaimsIdentity using the list of claims var claimsIdentity = new ClaimsIdentity(claimsList, "Token");
// Get the current ClaimsIdentity var claimsIdentity = (ClaimsIdentity)HttpContext.User.Identity; // Add a new claim to the ClaimsIdentity claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, "Manager"));These examples demonstrate how to create and add claims to a ClaimsIdentity object. The System.Security.Claims namespace provides all the necessary types for working with claims-based identity in .NET applications.