@@ -36,12 +36,12 @@ public class Saml2AuthnResponse : Saml2Response
3636 /// <summary>
3737 /// Gets the first instant in time at which this security token is valid.
3838 /// </summary>
39- public DateTime SecurityTokenValidFrom { get { return Saml2SecurityToken . ValidFrom ; } }
39+ public DateTimeOffset SecurityTokenValidFrom { get { return Saml2SecurityToken . ValidFrom ; } }
4040
4141 /// <summary>
4242 /// Gets the last instant in time at which this security token is valid.
4343 /// </summary>
44- public DateTime SecurityTokenValidTo { get { return Saml2SecurityToken . ValidTo ; } }
44+ public DateTimeOffset SecurityTokenValidTo { get { return Saml2SecurityToken . ValidTo ; } }
4545
4646 /// <summary>
4747 /// Saml2 Security Token Handler.
@@ -122,10 +122,11 @@ protected virtual SecurityTokenDescriptor CreateTokenDescriptor(IEnumerable<Clai
122122 {
123123 if ( Issuer == null ) throw new ArgumentNullException ( "Issuer property" ) ;
124124
125+ var now = DateTimeOffset . UtcNow ;
125126 var tokenDescriptor = new SecurityTokenDescriptor ( )
126127 {
127128 TokenType = SamlTokenTypes . Saml2TokenProfile11 . OriginalString ,
128- Lifetime = new Lifetime ( DateTime . UtcNow , DateTime . UtcNow . AddMinutes ( issuedTokenLifetime ) ) ,
129+ Lifetime = new Lifetime ( now . UtcDateTime , now . AddMinutes ( issuedTokenLifetime ) . UtcDateTime ) ,
129130 Subject = new ClaimsIdentity ( claims . Where ( c => c . Type != ClaimTypes . NameIdentifier ) ) ,
130131 AppliesToAddress = appliesToAddress . OriginalString ,
131132 TokenIssuerName = Issuer . OriginalString ,
@@ -141,7 +142,7 @@ protected virtual Saml2SubjectConfirmation CreateSubjectConfirmation(int subject
141142 var subjectConfirmationData = new Saml2SubjectConfirmationData
142143 {
143144 Recipient = Destination ,
144- NotOnOrAfter = DateTime . UtcNow . AddMinutes ( subjectConfirmationLifetime ) ,
145+ NotOnOrAfter = DateTimeOffset . UtcNow . AddMinutes ( subjectConfirmationLifetime ) . UtcDateTime ,
145146 } ;
146147
147148 if ( InResponseTo != null )
@@ -244,8 +245,8 @@ private void ValidateAssertionExpiration(XmlNode assertionElement)
244245 throw new Saml2RequestException ( "SubjectConfirmationData Not Found." ) ;
245246 }
246247
247- var notOnOrAfter = subjectConfirmationData . Attributes [ Saml2Constants . Message . NotOnOrAfter ] . GetValueOrNull < DateTime > ( ) ;
248- if ( notOnOrAfter < DateTime . UtcNow )
248+ var notOnOrAfter = subjectConfirmationData . Attributes [ Saml2Constants . Message . NotOnOrAfter ] . GetValueOrNull < DateTimeOffset > ( ) ;
249+ if ( notOnOrAfter < DateTimeOffset . UtcNow )
249250 {
250251 throw new Saml2RequestException ( $ "Assertion has expired. Assertion valid NotOnOrAfter { notOnOrAfter } .") ;
251252 }
0 commit comments