Represents an authentication claim.
This class is part of the System.Net.Security namespace.
public sealed class AuthenticationClaim
The AuthenticationClaim class is used to represent an authentication claim, which is a piece of information about a user or entity that is used in authentication and authorization processes. Claims are fundamental to modern identity management systems.
Each AuthenticationClaim object contains a claim type (e.g., "role", "name", "email") and a claim value (e.g., "Administrator", "John Doe", "john.doe@example.com").
This class is immutable, meaning once an AuthenticationClaim object is created, its properties cannot be changed.
System.Net.SecurityInitializes a new instance of the AuthenticationClaim class with the specified claim type and claim value.
Gets the type of the claim.
Gets the value of the claim.
Determines whether the specified object is equal to the current object.
Serves as the default hash function.
Returns a string that represents the current object.
This class has no public fields.
The following code example demonstrates how to create and use an AuthenticationClaim object.
using System;
using System.Net.Security;
public class Example
{
public static void Main(string[] args)
{
// Create an authentication claim for a user's role
AuthenticationClaim roleClaim = new AuthenticationClaim("role", "Administrator");
// Create an authentication claim for a user's name
AuthenticationClaim nameClaim = new AuthenticationClaim("name", "John Doe");
Console.WriteLine($"Claim Type: {roleClaim.ClaimType}, Claim Value: {roleClaim.ClaimValue}");
Console.WriteLine($"Claim Type: {nameClaim.ClaimType}, Claim Value: {nameClaim.ClaimValue}");
// Example of checking for equality
AuthenticationClaim anotherRoleClaim = new AuthenticationClaim("role", "Administrator");
if (roleClaim.Equals(anotherRoleClaim))
{
Console.WriteLine("The two role claims are equal.");
}
}
}