claimsCount++;
}
- return $"Identity Name = {Name ?? "(null)"}, IsAuthenticated = {(IsAuthenticated ? "true" : "false")}, Claims Count = {claimsCount}";
+ string debugText = $"IsAuthenticated = {(IsAuthenticated ? "true" : "false")}";
+ if (Name != null)
+ {
+ // The ClaimsIdentity.Name property requires that ClaimsIdentity.NameClaimType is correctly
+ // configured to match the name of the logical name claim type of the identity.
+ // Because of this, only include name if the ClaimsIdentity.Name property has a value.
+ // Not including the name is to avoid developer confusion at seeing "Name = (null)" on an authenticated identity.
+ debugText += $", Name = {Name}";
+ }
+ if (claimsCount > 0)
+ {
+ debugText += $", Claims = {claimsCount}";
+ }
+
+ return debugText;
}
private sealed class ClaimsIdentityDebugProxy
identitiesCount++;
}
- int claimsCount = 0;
- foreach (Claim item in Claims)
+ // Return debug string optimized for the case of one identity.
+ if (identitiesCount == 1 && Identity is ClaimsIdentity claimsIdentity)
{
- claimsCount++;
+ return claimsIdentity.DebuggerToString();
}
- // Return debug string optimized for the case of one identity.
- if (identitiesCount == 1 && Identity is ClaimsIdentity claimsIdentity)
+ int claimsCount = 0;
+ foreach (Claim item in Claims)
{
- return $"Principal {claimsIdentity.DebuggerToString()}";
+ claimsCount++;
}
- return $"Principal Identities Count: {identitiesCount}, Claims Count: {claimsCount}";
+ return $"Identities = {identitiesCount}, Claims = {claimsCount}";
}
private sealed class ClaimsPrincipalDebugProxy