From e65fcb2b0eb679a6eed0f8731a9d21a8e8d2dd5b Mon Sep 17 00:00:00 2001 From: Peter <34331512+pmaytak@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:26:04 -0700 Subject: [PATCH] Add JsonSerializerPrimitives.TryAllStringClaimsAsDateTime to 7x. (#2734) --- .../JwtTokenUtilities.cs | 2 +- .../Json/JsonSerializerPrimitives.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs index c83e5fddad..52b84a7b37 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs @@ -609,7 +609,7 @@ internal static string GetStringClaimValueType(string str) internal static string GetStringClaimValueType(string str, string claimType) { - if (!string.IsNullOrEmpty(claimType) && !AppContextSwitches.TryAllStringClaimsAsDateTime && JsonSerializerPrimitives.IsKnownToNotBeDateTime(claimType)) + if (!string.IsNullOrEmpty(claimType) && !JsonSerializerPrimitives.TryAllStringClaimsAsDateTime() && JsonSerializerPrimitives.IsKnownToNotBeDateTime(claimType)) return ClaimValueTypes.String; if (DateTime.TryParse(str, out DateTime dateTimeValue)) diff --git a/src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs b/src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs index c4f735e0cd..7a0b87978c 100644 --- a/src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs +++ b/src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs @@ -706,6 +706,11 @@ internal static string ReadStringOrNumberAsString(ref Utf8JsonReader reader, str return retVal; } + public static bool TryAllStringClaimsAsDateTime() + { + return AppContextSwitches.TryAllStringClaimsAsDateTime; + } + /// /// This is a non-exhaustive list of claim types that are not expected to be DateTime values /// sourced from expected Entra V1 and V2 claims, OpenID Connect claims, and a selection of