-
Notifications
You must be signed in to change notification settings - Fork 408
DateTimeOffset.UtcNow.DateTime.Kind == DateTimeKind.Unspecified
BrentSchmaltz edited this page Mar 10, 2022
·
2 revisions
When using DateTimeOffset.
Consider the following code:
JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(expires: DateTimeOffset.UtcNow.DateTime.AddMinutes(15));
The DateTime instance passed to the ctor, will have the UTC time, but the Kind property will be DateTimeKind.Unspecified. Internally
EpochTime.GetIntDate(DateTime);
will get called where DateTime.ToUniversalTime() will be called and the UTC time will be changed.
Most likely this is not what the use wants.
The following will work as expected.
JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(expires: DateTimeOffset.DateTime.AddMinutes(15));
JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(expires: DateTime.UtcNow.AddMinutes(15));
JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(expires: DateTime.Now.AddMinutes(15));
Conceptual Documentation
- Using TokenValidationParameters.ValidateIssuerSigningKey
- Scenarios
- Validating tokens
- Outbound policy claim type mapping
- How ASP.NET Core uses Microsoft.IdentityModel extensions for .NET
- Using a custom CryptoProvider
- SignedHttpRequest aka PoP (Proof-of-Possession)
- Creating and Validating JWEs (Json Web Encryptions)
- Caching in Microsoft.IdentityModel
- Resiliency on metadata refresh
- Use KeyVault extensions
- Signing key roll over