@@ -846,6 +846,47 @@ public async Task ExpirationAndIssuedSetOnAuthenticateResult()
846
846
Assert . Equal ( token . ValidFrom , dom . RootElement . GetProperty ( "issued" ) . GetDateTimeOffset ( ) ) ;
847
847
}
848
848
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
+
849
890
class InvalidTokenValidator : ISecurityTokenValidator
850
891
{
851
892
public InvalidTokenValidator ( )
@@ -1065,7 +1106,7 @@ private static async Task<IHost> CreateHost(Action<JwtBearerOptions> options = n
1065
1106
{
1066
1107
var authenticationResult = await context . AuthenticateAsync ( JwtBearerDefaults . AuthenticationScheme ) ;
1067
1108
await context . Response . WriteAsJsonAsync (
1068
- new { Expires = authenticationResult . Properties . ExpiresUtc , Issued = authenticationResult . Properties . IssuedUtc } ) ;
1109
+ new { Expires = authenticationResult . Properties ? . ExpiresUtc , Issued = authenticationResult . Properties ? . IssuedUtc } ) ;
1069
1110
}
1070
1111
else
1071
1112
{
0 commit comments