TryReadJwtClaim Delegate

Definition

When JSON Web Token header or payload is being read claim by claim, this delegate is called after all claims known to the library have been processed. When called, the reader is positioned at the claim value.

public delegate bool TryReadJwtClaim(ref Utf8JsonReader reader, JwtSegmentType jwtSegmentType, string claimName, out object claimValue);
type TryReadJwtClaim = delegate of Utf8JsonReader * JwtSegmentType * string * obj -> bool
Public Delegate Function TryReadJwtClaim(ByRef reader As Utf8JsonReader, jwtSegmentType As JwtSegmentType, claimName As String, ByRef claimValue As Object) As Boolean 

Parameters

reader
Utf8JsonReader

Reader for the underlying token bytes.

jwtSegmentType
JwtSegmentType

Specifies whether the claim is from the JWT header or payload.

claimName
String

The claim name for this claim value.

claimValue
Object

The claim value that was read and parsed from the reader.

Return Value

True, if the claim value was read successfully; false otherwise.

Remarks

An example implementation:

bool TryReadJwtClaim(ref Utf8JsonReader reader, JwtSegmentType jwtSegmentType, string claimName, out object claimValue)
{
    if (jwtSegmentType == JwtSegmentType.Payload && claimName == "CustomClaimName")
        claimValue = JsonSerializer.Deserialize<CustomClaim>(reader.GetString());
        return true;
    return false;
}

Applies to