Table of Contents

Class ClaimsExtensions

Namespace
Tharga.Toolkit
Assembly
Tharga.Toolkit.dll

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

identityKey IdentityKey

Returns

IEnumerable<(string Identity, string Type)>

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

identityKey IdentityKey

The identity key to search.

type string

The claim type to look up.

Returns

string

The identity value, or null if 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

claims IEnumerable<Claim>

Returns

IdentityKey

GetKey(ClaimsIdentity)

Extracts an IdentityKey from the claims identity.

public static IdentityKey GetKey(this ClaimsIdentity claimsIdentity)

Parameters

claimsIdentity ClaimsIdentity

Returns

IdentityKey

GetKey(ClaimsPrincipal)

Extracts an IdentityKey from the claims principal's identity claims.

public static IdentityKey GetKey(this ClaimsPrincipal claimsPrincipal)

Parameters

claimsPrincipal ClaimsPrincipal

The claims principal to extract the key from.

Returns

IdentityKey

An IdentityKey, or null if 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

identityKey IdentityKey
identity string
type string

Returns

bool

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

identityKey IdentityKey

The identity key to verify against.

key (string Identity, string Type)

A tuple of identity value and claim type to match.

Returns

bool

true if the identity key contains the specified identity.