Given I create a claims identity and subsequently a principal. Then I serialize the principal. Inspecting the json string I can confirm that the "Role" claim is there as well as the identity.
Deserializing it back results in an object with empty properties. The .Claims
and .Identity
is lost.
var identity = new ClaimsIdentity(new List<Claim>() { new Claim("Role", "Admin") });
var principal = new ClaimsPrincipal(identity);
string serialized = JsonConvert.SerializeObject(principal, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
ClaimsPrincipal deserialized = JsonConvert.DeserializeObject<ClaimsPrincipal>(serialized); // The object has all properties empty
Question: How can I ensure the object is correctly deserialized?