diff --git a/src/OpenIddict.Client/OpenIddictClientOptions.cs b/src/OpenIddict.Client/OpenIddictClientOptions.cs index 8f396b4e0..7edf7e96f 100644 --- a/src/OpenIddict.Client/OpenIddictClientOptions.cs +++ b/src/OpenIddict.Client/OpenIddictClientOptions.cs @@ -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)) { diff --git a/src/OpenIddict.Client/OpenIddictClientRegistration.cs b/src/OpenIddict.Client/OpenIddictClientRegistration.cs index b77572e47..933f91217 100644 --- a/src/OpenIddict.Client/OpenIddictClientRegistration.cs +++ b/src/OpenIddict.Client/OpenIddictClientRegistration.cs @@ -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)) { diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs index 286dcb184..2f9845b15 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs @@ -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)) diff --git a/src/OpenIddict.Server/OpenIddictServerOptions.cs b/src/OpenIddict.Server/OpenIddictServerOptions.cs index 983b1681a..58f9aaad1 100644 --- a/src/OpenIddict.Server/OpenIddictServerOptions.cs +++ b/src/OpenIddict.Server/OpenIddictServerOptions.cs @@ -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. diff --git a/src/OpenIddict.Validation/OpenIddictValidationOptions.cs b/src/OpenIddict.Validation/OpenIddictValidationOptions.cs index 687d12d38..70e5de170 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationOptions.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationOptions.cs @@ -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.