MSDN Library

System.Net.Security.AuthenticationClaim Class

Represents an authentication claim.

This class is part of the System.Net.Security namespace.

Syntax


public sealed class AuthenticationClaim
            

Remarks

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.

Inheritance Hierarchy

Requirements

Namespace
System.Net.Security
Assembly
System.Net.Primitives.dll

Constructors

Properties

Methods

Fields

This class has no public fields.

Examples

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.");
        }
    }
}