Skip to content

JwtTypeName Class

Compares JWT typ header values, which name a media type and therefore have more than one spelling for the same value.

C#
public static class JwtTypeName

Inheritance System.Object → JwtTypeName

Remarks

Two rules make the spellings equivalent. RFC 7515 Section 4.1.9: "A recipient using the media type value MUST treat it as if 'application/' were prepended to any 'typ' value not containing a '/'", so at+jwt and application/at+jwt are one name. RFC 2045 Section 5.1: "Matching of media type and subtype is ALWAYS case-insensitive", so casing carries no meaning either. Note that RFC 7515 Section 5.3, which defines this library's general string-comparison rules, does not apply: it ends by exempting exactly this parameter, "Only the 'typ' and 'cty' member values defined in this specification do not use these comparison rules". This lives here rather than beside each comparison so the rule has one implementation: a second copy would be a second, quietly different answer to "is this an access token".

Methods

JwtTypeName.Matches(string, string) Method

Determines whether two typ values name the same token type, in any spelling of either.

C#
public static bool Matches(string? actual, string expected);

Parameters

actual System.String

The value read from the token's header, or null when it carries none.

expected System.String

The value the caller expects, written in whichever spelling it prefers.

Returns

System.Boolean
true when both name the same media type.

JwtTypeName.StripApplicationPrefix(string) Method

Removes the application/ prefix when present, reaching RFC 7515 Section 4.1.9's equivalence from either form rather than only from the short one.

C#
public static string StripApplicationPrefix(string typ);

Parameters

typ System.String

The typ value to normalise.

Returns

System.String
The value without its media-type prefix.

Remarks

The prefix match ignores case because it is the media type portion, which RFC 2045 Section 5.1 declares case-insensitive; matching it ordinally would leave Application/at+jwt unstripped and therefore unmatchable.