Skip to content

Commit 4d4ceb6

Browse files
committed
Debug ports changed.
Use DateTimeOffset instead of DateTime.
1 parent 8515054 commit 4d4ceb6

File tree

11 files changed

+26
-43
lines changed

11 files changed

+26
-43
lines changed

src/ITfoxtec.Identity.Saml2.MvcCore/Extensions/Saml2ResponseExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ await httpContext.SignInAsync(Saml2Constants.AuthenticationScheme, principal,
4444
{
4545
AllowRefresh = false,
4646
IsPersistent = isPersistent,
47-
IssuedUtc = new DateTimeOffset(saml2AuthnResponse.SecurityTokenValidFrom),
48-
ExpiresUtc = lifetime.HasValue ? new DateTimeOffset(DateTime.UtcNow + lifetime.Value) : new DateTimeOffset(saml2AuthnResponse.SecurityTokenValidTo),
47+
IssuedUtc = saml2AuthnResponse.SecurityTokenValidFrom,
48+
ExpiresUtc = lifetime.HasValue ? DateTimeOffset.UtcNow.Add(lifetime.Value) : saml2AuthnResponse.SecurityTokenValidTo,
4949
});
5050

5151
return principal;

src/ITfoxtec.Identity.Saml2/Request/Saml2AuthnResponse.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/ITfoxtec.Identity.Saml2/Request/Saml2LogoutRequest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Saml2LogoutRequest : Saml2Request
2323
/// The time at which the request expires, after which the recipient may discard the message. The time
2424
/// value is encoded in UTC, as described in Section 1.3.3.
2525
/// </summary>
26-
public DateTime? NotOnOrAfter { get; set; }
26+
public DateTimeOffset? NotOnOrAfter { get; set; }
2727

2828
/// <summary>
2929
/// [Optional]
@@ -36,7 +36,7 @@ public Saml2LogoutRequest(Saml2Configuration config) : base(config)
3636
if (config == null) throw new ArgumentNullException(nameof(config));
3737

3838
Destination = config.SingleLogoutDestination;
39-
NotOnOrAfter = DateTime.UtcNow.AddMinutes(10);
39+
NotOnOrAfter = DateTimeOffset.UtcNow.AddMinutes(10);
4040
}
4141

4242
public Saml2LogoutRequest(Saml2Configuration config, ClaimsPrincipal currentPrincipal) : this(config)
@@ -81,7 +81,7 @@ protected override IEnumerable<XObject> GetXContent()
8181
{
8282
if (NotOnOrAfter.HasValue)
8383
{
84-
yield return new XAttribute(Saml2Constants.Message.NotOnOrAfter, NotOnOrAfter.Value.ToString("o", CultureInfo.InvariantCulture));
84+
yield return new XAttribute(Saml2Constants.Message.NotOnOrAfter, NotOnOrAfter.Value.UtcDateTime.ToString("o", CultureInfo.InvariantCulture));
8585
}
8686

8787
if (Reason != null)

src/ITfoxtec.Identity.Saml2/Request/Saml2Request.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public string IdAsString
5252
/// [Required]
5353
/// The time instant of issue of the request. The time value is encoded in UTC, as described in Section 1.3.3.
5454
/// </summary>
55-
public DateTime IssueInstant { get; set; }
55+
public DateTimeOffset IssueInstant { get; set; }
5656

5757
/// <summary>
5858
/// [Optional]
@@ -119,7 +119,7 @@ public Saml2Request(Saml2Configuration config)
119119

120120
Id = new Saml2Id();
121121
Version = Saml2Constants.VersionNumber;
122-
IssueInstant = DateTime.UtcNow;
122+
IssueInstant = DateTimeOffset.UtcNow;
123123
#if DEBUG
124124
Debug.WriteLine("Message ID: " + Id);
125125
#endif
@@ -131,7 +131,7 @@ protected virtual IEnumerable<XObject> GetXContent()
131131
yield return new XAttribute(Saml2Constants.AssertionNamespaceNameX, Saml2Constants.AssertionNamespace.OriginalString);
132132
yield return new XAttribute(Saml2Constants.Message.Id, Id);
133133
yield return new XAttribute(Saml2Constants.Message.Version, Version);
134-
yield return new XAttribute(Saml2Constants.Message.IssueInstant, IssueInstant.ToString("o", CultureInfo.InvariantCulture));
134+
yield return new XAttribute(Saml2Constants.Message.IssueInstant, IssueInstant.UtcDateTime.ToString("o", CultureInfo.InvariantCulture));
135135

136136
if (!string.IsNullOrWhiteSpace(Consent))
137137
{
@@ -179,7 +179,7 @@ protected internal virtual void Read(string xml, bool validateXmlSignature)
179179
throw new Saml2RequestException("Invalid SAML2 version.");
180180
}
181181

182-
IssueInstant = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.IssueInstant].GetValueOrNull<DateTime>();
182+
IssueInstant = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.IssueInstant].GetValueOrNull<DateTimeOffset>();
183183

184184
Issuer = XmlDocument.DocumentElement[Saml2Constants.Message.Issuer, Saml2Constants.AssertionNamespace.OriginalString].GetValueOrNull<Uri>();
185185

src/ITfoxtec.Identity.Saml2/Schemas/Metadata/EntityDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected IEnumerable<XObject> GetXContent()
115115
yield return new XAttribute(Saml2MetadataConstants.Message.Id, Id);
116116
if (ValidUntil.HasValue)
117117
{
118-
yield return new XAttribute(Saml2MetadataConstants.Message.ValidUntil, DateTime.UtcNow.AddDays(ValidUntil.Value).ToString("o", CultureInfo.InvariantCulture));
118+
yield return new XAttribute(Saml2MetadataConstants.Message.ValidUntil, DateTimeOffset.UtcNow.AddDays(ValidUntil.Value).UtcDateTime.ToString("o", CultureInfo.InvariantCulture));
119119
}
120120
yield return new XAttribute(Saml2MetadataConstants.MetadataNamespaceNameX, Saml2MetadataConstants.MetadataNamespace);
121121

src/ITfoxtec.Identity.Saml2/Util/GenericTypeConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ internal static T ConvertValue<T>(string value, XmlNode xmlNode)
2424
{
2525
return GenericConvertValue<T, Saml2Id>(new Saml2Id(value));
2626
}
27-
if (genericType == typeof(DateTime))
27+
if (genericType == typeof(DateTimeOffset))
2828
{
29-
return GenericConvertValue<T, DateTime>(DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal));
29+
return GenericConvertValue<T, DateTimeOffset>(DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal));
3030
}
3131
if(genericType == typeof(Saml2NameIdentifier))
3232
{

test/TestIdPCore/Properties/launchSettings.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,14 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:2907/",
7-
"sslPort": 44341
6+
"applicationUrl": "http://localhost:3111/",
7+
"sslPort": 44305
88
}
99
},
1010
"profiles": {
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
14-
"launchUrl": "https://localhost:44341/",
15-
"environmentVariables": {
16-
"ASPNETCORE_ENVIRONMENT": "Development"
17-
}
18-
},
19-
"TestIdPCore": {
20-
"commandName": "Project",
21-
"launchBrowser": true,
22-
"launchUrl": "http://localhost:5000",
2314
"environmentVariables": {
2415
"ASPNETCORE_ENVIRONMENT": "Development"
2516
}

test/TestIdPCore/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"Saml2": {
1111
"Issuer": "urn:itfoxtec:identity:saml2:testidpcore",
12-
"SingleSignOnDestination": "https://localhost:44341/Auth/Login",
13-
"SingleLogoutDestination": "https://localhost:44341/Auth/Logout",
12+
"SingleSignOnDestination": "https://localhost:44305/Auth/Login",
13+
"SingleLogoutDestination": "https://localhost:44305/Auth/Logout",
1414
"SignatureAlgorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
1515
"SigningCertificateFile": "itfoxtec.identity.saml2.testidpcore_Certificate.pfx",
1616
"SigningCertificatePassword": "!QAZ2wsx",

test/TestWebApp/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<add key="webpages:Enabled" value="false" />
1414
<add key="ClientValidationEnabled" value="true" />
1515
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
16-
<add key="Saml2:IdPMetadata" value="https://localhost:44341/metadata" />
16+
<add key="Saml2:IdPMetadata" value="https://localhost:44305/metadata" />
1717
<add key="Saml2:Issuer" value="urn:itfoxtec:identity:saml2:testwebapp" />
1818
<add key="Saml2:SingleSignOnDestination" value="https://test-adfs.itfoxtec.com/adfs/ls/" />
1919
<add key="Saml2:SingleLogoutDestination" value="https://test-adfs.itfoxtec.com/adfs/ls/" />

test/TestWebAppCore/Properties/launchSettings.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,14 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:2574/",
6+
"applicationUrl": "http://localhost:3113/",
77
"sslPort": 44306
88
}
99
},
1010
"profiles": {
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
14-
"launchUrl": "https://localhost:44306/",
15-
"environmentVariables": {
16-
"ASPNETCORE_ENVIRONMENT": "Development"
17-
}
18-
},
19-
"TestWebAppCore": {
20-
"commandName": "Project",
21-
"launchBrowser": true,
22-
"launchUrl": "http://localhost:5000",
2314
"environmentVariables": {
2415
"ASPNETCORE_ENVIRONMENT": "Development"
2516
}

0 commit comments

Comments
 (0)