Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/OpenIddict.Client/OpenIddictClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ public sealed class OpenIddictClientOptions
ClockSkew = TimeSpan.Zero,
NameClaimType = Claims.Name,
RoleClaimType = Claims.Role,
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
TypeValidator = static (type, token, parameters) =>
{
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
if (string.IsNullOrEmpty(type))
{
type = JsonWebTokenTypes.GenericJsonWebToken;
}

// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))
{
Expand Down
8 changes: 7 additions & 1 deletion src/OpenIddict.Client/OpenIddictClientRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,15 @@ public sealed class OpenIddictClientRegistration
ClockSkew = TimeSpan.Zero,
NameClaimType = Claims.Name,
RoleClaimType = Claims.Role,
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
TypeValidator = static (type, token, parameters) =>
{
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
if (string.IsNullOrEmpty(type))
{
type = JsonWebTokenTypes.GenericJsonWebToken;
}

// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))
{
Expand Down
6 changes: 6 additions & 0 deletions src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ TokenValidationParameters GetClientTokenValidationParameters()
{
TypeValidator = static (type, token, parameters) =>
{
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
if (string.IsNullOrEmpty(type))
{
type = JsonWebTokenTypes.GenericJsonWebToken;
}

// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))
Expand Down
5 changes: 2 additions & 3 deletions src/OpenIddict.Server/OpenIddictServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ public sealed class OpenIddictServerOptions
};
}

// At this point, throw an exception if the type cannot be resolved from the "typ" header
// (provided via the type delegate parameter) or inferred from the token_usage claim.
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
if (string.IsNullOrEmpty(type))
{
throw new SecurityTokenInvalidTypeException(SR.GetResourceString(SR.ID0270));
type = JsonWebTokenTypes.GenericJsonWebToken;
}

// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
Expand Down
5 changes: 2 additions & 3 deletions src/OpenIddict.Validation/OpenIddictValidationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,10 @@ public sealed class OpenIddictValidationOptions
};
}

// At this point, throw an exception if the type cannot be resolved from the "typ" header
// (provided via the type delegate parameter) or inferred from the token_usage claim.
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
if (string.IsNullOrEmpty(type))
{
throw new SecurityTokenInvalidTypeException(SR.GetResourceString(SR.ID0270));
type = JsonWebTokenTypes.GenericJsonWebToken;
}

// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
Expand Down