Class ClaimsExtensions
Extension methods for extracting and verifying identity keys from claims. Works with IdentityKey to provide a portable, serialized identity representation.
public static class ClaimsExtensions
- Inheritance
-
ClaimsExtensions
- Inherited Members
Methods
GetIdentities(IdentityKey)
Extracts all identity/type pairs stored in the identity key.
public static IEnumerable<(string Identity, string Type)> GetIdentities(this IdentityKey identityKey)
Parameters
identityKeyIdentityKey
Returns
GetIdentity(IdentityKey, string)
Gets the identity value for a specific claim type from the identity key.
public static string GetIdentity(this IdentityKey identityKey, string type)
Parameters
identityKeyIdentityKeyThe identity key to search.
typestringThe claim type to look up.
Returns
- string
The identity value, or
nullif the type is not found.
GetKey(IEnumerable<Claim>)
Extracts an IdentityKey from a collection of claims by matching known identity claim types.
public static IdentityKey GetKey(this IEnumerable<Claim> claims)
Parameters
claimsIEnumerable<Claim>
Returns
GetKey(ClaimsIdentity)
Extracts an IdentityKey from the claims identity.
public static IdentityKey GetKey(this ClaimsIdentity claimsIdentity)
Parameters
claimsIdentityClaimsIdentity
Returns
GetKey(ClaimsPrincipal)
Extracts an IdentityKey from the claims principal's identity claims.
public static IdentityKey GetKey(this ClaimsPrincipal claimsPrincipal)
Parameters
claimsPrincipalClaimsPrincipalThe claims principal to extract the key from.
Returns
- IdentityKey
An IdentityKey, or
nullif no recognized identity claims are found.
VerifyKey(IdentityKey, string, string)
Verifies whether the identity key contains the specified identity, optionally filtered by claim type.
public static bool VerifyKey(this IdentityKey identityKey, string identity, string type = null)
Parameters
identityKeyIdentityKeyidentitystringtypestring
Returns
VerifyKey(IdentityKey, (string Identity, string Type))
Verifies whether the identity key contains the specified identity.
public static bool VerifyKey(this IdentityKey identityKey, (string Identity, string Type) key)
Parameters
identityKeyIdentityKeyThe identity key to verify against.
key(string Identity, string Type)A tuple of identity value and claim type to match.
Returns
- bool
trueif the identity key contains the specified identity.