Skip to content

Commit 55cd0e9

Browse files
committed
Update all the token type validation delegates to assume that tokens that don't have a "typ" header are generic JSON Web Tokens
1 parent 91a68c1 commit 55cd0e9

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

src/OpenIddict.Client/OpenIddictClientOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,15 @@ public sealed class OpenIddictClientOptions
113113
ClockSkew = TimeSpan.Zero,
114114
NameClaimType = Claims.Name,
115115
RoleClaimType = Claims.Role,
116-
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
117116
TypeValidator = static (type, token, parameters) =>
118117
{
118+
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
119+
if (string.IsNullOrEmpty(type))
120+
{
121+
type = JsonWebTokenTypes.GenericJsonWebToken;
122+
}
123+
124+
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
119125
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
120126
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))
121127
{

src/OpenIddict.Client/OpenIddictClientRegistration.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,15 @@ public sealed class OpenIddictClientRegistration
190190
ClockSkew = TimeSpan.Zero,
191191
NameClaimType = Claims.Name,
192192
RoleClaimType = Claims.Role,
193-
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
194193
TypeValidator = static (type, token, parameters) =>
195194
{
195+
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
196+
if (string.IsNullOrEmpty(type))
197+
{
198+
type = JsonWebTokenTypes.GenericJsonWebToken;
199+
}
200+
201+
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
196202
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
197203
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))
198204
{

src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ TokenValidationParameters GetClientTokenValidationParameters()
119119
{
120120
TypeValidator = static (type, token, parameters) =>
121121
{
122+
// Assume that tokens that don't have an explicit "typ" header attached are generic JSON Web Tokens.
123+
if (string.IsNullOrEmpty(type))
124+
{
125+
type = JsonWebTokenTypes.GenericJsonWebToken;
126+
}
127+
122128
// Note: unlike IdentityModel, this custom validator deliberately uses case-insensitive comparisons.
123129
if (parameters.ValidTypes is not null && parameters.ValidTypes.Any() &&
124130
!parameters.ValidTypes.Contains(type, StringComparer.OrdinalIgnoreCase))

src/OpenIddict.Server/OpenIddictServerOptions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ public sealed class OpenIddictServerOptions
154154
};
155155
}
156156

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

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

src/OpenIddict.Validation/OpenIddictValidationOptions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ public sealed class OpenIddictValidationOptions
185185
};
186186
}
187187

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

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

0 commit comments

Comments
 (0)