PrincipalExtensions Class

Summary

Claims related extensions for System.Security.Claims.ClaimsPrincipal.

Syntax

public class PrincipalExtensions

GitHub

View on GitHub

class System.Security.Claims.PrincipalExtensions

Methods

FindFirstValue(System.Security.Claims.ClaimsPrincipal, System.String)

Returns the value for the first claim of the specified type otherwise null the claim is not present.

Arguments:
  • principal (System.Security.Claims.ClaimsPrincipal) – The System.Security.Claims.ClaimsPrincipal instance this method extends.
  • claimType (System.String) – The claim type whose first value should be returned.
Return type:

System.String

Returns:

The value of the first instance of the specified claim type, or null if the claim is not present.

public static string FindFirstValue(ClaimsPrincipal principal, string claimType)
GetUserId(System.Security.Claims.ClaimsPrincipal)

Returns the User ID claim value if present otherwise returns null.

Arguments:
  • principal (System.Security.Claims.ClaimsPrincipal) – The System.Security.Claims.ClaimsPrincipal instance this method extends.
Return type:

System.String

Returns:

The User ID claim value, or null if the claim is not present.

public static string GetUserId(ClaimsPrincipal principal)
GetUserName(System.Security.Claims.ClaimsPrincipal)

Returns the Name claim value if present otherwise returns null.

Arguments:
  • principal (System.Security.Claims.ClaimsPrincipal) – The System.Security.Claims.ClaimsPrincipal instance this method extends.
Return type:

System.String

Returns:

The Name claim value, or null if the claim is not present.

public static string GetUserName(ClaimsPrincipal principal)
IsSignedIn(System.Security.Claims.ClaimsPrincipal)

Returns true if the principal has an identity with the application cookie identity

Arguments:
  • principal (System.Security.Claims.ClaimsPrincipal) – The System.Security.Claims.ClaimsPrincipal instance this method extends.
Return type:

System.Boolean

Returns:

True if the user is logged in with identity.

public static bool IsSignedIn(ClaimsPrincipal principal)