Skip to content

Commit

Permalink
Use TimeProvider in ValidateLifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Aug 7, 2024
1 parent 20bcf69 commit c7265b9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Microsoft.IdentityModel.Tokens/ValidatorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ internal static void ValidateLifetime(DateTime? notBefore, DateTime? expires, Se
Expires = expires
});

#if SUPPORTS_TIME_PROVIDER
DateTime utcNow = validationParameters.TimeProvider?.GetUtcNow().UtcDateTime ?? DateTime.UtcNow;
#else
DateTime utcNow = DateTime.UtcNow;
#endif
if (notBefore.HasValue && (notBefore.Value > DateTimeUtil.Add(utcNow, validationParameters.ClockSkew)))
throw LogHelper.LogExceptionMessage(new SecurityTokenNotYetValidException(LogHelper.FormatInvariant(LogMessages.IDX10222, LogHelper.MarkAsNonPII(notBefore.Value), LogHelper.MarkAsNonPII(utcNow)))
{
Expand Down

0 comments on commit c7265b9

Please sign in to comment.