@@ -846,6 +846,47 @@ public async Task ExpirationAndIssuedSetOnAuthenticateResult()
846846 Assert . Equal ( token . ValidFrom , dom . RootElement . GetProperty ( "issued" ) . GetDateTimeOffset ( ) ) ;
847847 }
848848
849+ [ Fact ]
850+ public async Task ExpirationAndIssuedNullWhenMinOrMaxValue ( )
851+ {
852+ var key = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( new string ( 'a' , 128 ) ) ) ;
853+ var creds = new SigningCredentials ( key , SecurityAlgorithms . HmacSha256 ) ;
854+
855+ var claims = new [ ]
856+ {
857+ new Claim ( ClaimTypes . NameIdentifier , "Bob" )
858+ } ;
859+
860+ var token = new JwtSecurityToken (
861+ issuer : "issuer.contoso.com" ,
862+ audience : "audience.contoso.com" ,
863+ claims : claims ,
864+ expires : DateTime . MaxValue ,
865+ signingCredentials : creds ) ;
866+
867+ var tokenText = new JwtSecurityTokenHandler ( ) . WriteToken ( token ) ;
868+
869+ using var host = await CreateHost ( o =>
870+ {
871+ o . SaveToken = true ;
872+ o . TokenValidationParameters = new TokenValidationParameters ( )
873+ {
874+ ValidIssuer = "issuer.contoso.com" ,
875+ ValidAudience = "audience.contoso.com" ,
876+ IssuerSigningKey = key ,
877+ } ;
878+ } ) ;
879+
880+ var newBearerToken = "Bearer " + tokenText ;
881+ using var server = host . GetTestServer ( ) ;
882+ var response = await SendAsync ( server , "http://example.com/expiration" , newBearerToken ) ;
883+ Assert . Equal ( HttpStatusCode . OK , response . Response . StatusCode ) ;
884+ var responseBody = await response . Response . Content . ReadAsStringAsync ( ) ;
885+ using var dom = JsonDocument . Parse ( responseBody ) ;
886+ Assert . Equal ( JsonValueKind . Null , dom . RootElement . GetProperty ( "expires" ) . ValueKind ) ;
887+ Assert . Equal ( JsonValueKind . Null , dom . RootElement . GetProperty ( "issued" ) . ValueKind ) ;
888+ }
889+
849890 class InvalidTokenValidator : ISecurityTokenValidator
850891 {
851892 public InvalidTokenValidator ( )
@@ -1065,7 +1106,7 @@ private static async Task<IHost> CreateHost(Action<JwtBearerOptions> options = n
10651106 {
10661107 var authenticationResult = await context . AuthenticateAsync ( JwtBearerDefaults . AuthenticationScheme ) ;
10671108 await context . Response . WriteAsJsonAsync (
1068- new { Expires = authenticationResult . Properties . ExpiresUtc , Issued = authenticationResult . Properties . IssuedUtc } ) ;
1109+ new { Expires = authenticationResult . Properties ? . ExpiresUtc , Issued = authenticationResult . Properties ? . IssuedUtc } ) ;
10691110 }
10701111 else
10711112 {
0 commit comments