Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 2d19b89

Browse files
author
Nate McMaster
committed
Revert obsoleting CookieAuthenticationOptions.ExpireTimeSpan
1 parent a7bf561 commit 2d19b89

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ public async virtual Task SignInAsync(ClaimsPrincipal user, AuthenticationProper
270270

271271
if (!signInContext.Properties.ExpiresUtc.HasValue)
272272
{
273-
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.Cookie.Expiration ?? default(TimeSpan));
273+
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
274274
}
275275

276276
await Events.SigningIn(signInContext);
277277

278278
if (signInContext.Properties.IsPersistent)
279279
{
280-
var expiresUtc = signInContext.Properties.ExpiresUtc ?? issuedUtc.Add(Options.Cookie.Expiration ?? default(TimeSpan));
280+
var expiresUtc = signInContext.Properties.ExpiresUtc ?? issuedUtc.Add(Options.ExpireTimeSpan);
281281
signInContext.CookieOptions.Expires = expiresUtc.ToUniversalTime();
282282
}
283283

src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationOptions.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public class CookieAuthenticationOptions : AuthenticationSchemeOptions
2121
SameSite = SameSiteMode.Lax,
2222
HttpOnly = true,
2323
SecurePolicy = CookieSecurePolicy.SameAsRequest,
24-
Expiration = TimeSpan.FromDays(14),
2524
};
2625

2726
/// <summary>
2827
/// Create an instance of the options initialized with the default values
2928
/// </summary>
3029
public CookieAuthenticationOptions()
3130
{
31+
ExpireTimeSpan = TimeSpan.FromDays(14);
3232
ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
3333
SlidingExpiration = true;
3434
Events = new CookieAuthenticationEvents();
@@ -42,7 +42,6 @@ public CookieAuthenticationOptions()
4242
/// <seealso cref="CookieBuilder.SameSite"/> defaults to <see cref="SameSiteMode.Lax"/>.
4343
/// <seealso cref="CookieBuilder.HttpOnly"/> defaults to <c>true</c>.
4444
/// <seealso cref="CookieBuilder.SecurePolicy"/> defaults to <see cref="CookieSecurePolicy.SameAsRequest"/>.
45-
/// <seealso cref="CookieBuilder.Expiration"/> defaults to 14 days.
4645
/// </para>
4746
/// </summary>
4847
/// <remarks>
@@ -60,9 +59,7 @@ public CookieAuthenticationOptions()
6059
/// The default is true, which means the cookie will only be passed to http requests and is not made available to script on the page.
6160
/// </para>
6261
/// <para>
63-
/// <seealso cref="CookieBuilder.Expiration"/> controls how much time the cookie will remain valid from the point it is created. The expiration
64-
/// information is in the protected cookie ticket. Because of that an expired cookie will be ignored
65-
/// even if it is passed to the server after the browser should have purged it
62+
/// <seealso cref="CookieBuilder.Expiration"/> is currently ignored. <see cref="ExpireTimeSpan"/>.
6663
/// </para>
6764
/// </remarks>
6865
public CookieBuilder Cookie
@@ -140,6 +137,19 @@ public CookieBuilder Cookie
140137
/// </summary>
141138
public ITicketStore SessionStore { get; set; }
142139

140+
/// <summary>
141+
/// <para>
142+
/// Controls how much time the authentication ticket stored in the cookie will remain valid from the point it is created
143+
/// The expiration information is stored in the protected cookie ticket. Because of that an expired cookie will be ignored
144+
/// even if it is passed to the server after the browser should have purged it.
145+
/// </para>
146+
/// <para>
147+
/// This is separate from the value of <seealso cref="CookieOptions.Expires"/>, which specifies
148+
/// how long the browser will keep the cookie.
149+
/// </para>
150+
/// </summary>
151+
public TimeSpan ExpireTimeSpan { get; set; }
152+
143153
#region Obsolete API
144154
/// <summary>
145155
/// <para>
@@ -201,23 +211,6 @@ public CookieBuilder Cookie
201211
/// </summary>
202212
[Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.SecurePolicy) + ".")]
203213
public CookieSecurePolicy CookieSecure { get => Cookie.SecurePolicy; set => Cookie.SecurePolicy = value; }
204-
205-
/// <summary>
206-
/// <para>
207-
/// This property is obsolete and will be removed in a future version. The recommended alternative is <seealso cref="CookieBuilder.Expiration"/> on <see cref="Cookie"/>.
208-
/// </para>
209-
/// <para>
210-
/// Controls how much time the cookie will remain valid from the point it is created. The expiration
211-
/// information is in the protected cookie ticket. Because of that an expired cookie will be ignored
212-
/// even if it is passed to the server after the browser should have purged it
213-
/// </para>
214-
/// </summary>
215-
[Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Expiration) + ".")]
216-
public TimeSpan ExpireTimeSpan
217-
{
218-
get => Cookie.Expiration ?? default(TimeSpan);
219-
set => Cookie.Expiration = value;
220-
}
221214
#endregion
222215
}
223216
}

src/Microsoft.AspNetCore.Authentication.Cookies/Microsoft.AspNetCore.Authentication.Cookies.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,4 @@
1919
<ProjectReference Include="..\Microsoft.AspNetCore.Authentication\Microsoft.AspNetCore.Authentication.csproj" />
2020
</ItemGroup>
2121

22-
<ItemGroup>
23-
<Folder Include="Properties\" />
24-
</ItemGroup>
25-
2622
</Project>

test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public async Task CookieStopsWorkingAfterExpiration()
277277
{
278278
var server = CreateServer(o =>
279279
{
280-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
280+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
281281
o.SlidingExpiration = false;
282282
}, SignInAsAlice);
283283

@@ -306,7 +306,7 @@ public async Task CookieExpirationCanBeOverridenInSignin()
306306
{
307307
var server = CreateServer(o =>
308308
{
309-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
309+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
310310
o.SlidingExpiration = false;
311311
},
312312
context =>
@@ -339,7 +339,7 @@ public async Task ExpiredCookieWithValidatorStillExpired()
339339
{
340340
var server = CreateServer(o =>
341341
{
342-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
342+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
343343
o.Events = new CookieAuthenticationEvents
344344
{
345345
OnValidatePrincipal = ctx =>
@@ -367,7 +367,7 @@ public async Task CookieCanBeRejectedAndSignedOutByValidator()
367367
{
368368
var server = CreateServer(o =>
369369
{
370-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
370+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
371371
o.SlidingExpiration = false;
372372
o.Events = new CookieAuthenticationEvents
373373
{
@@ -395,7 +395,7 @@ public async Task CookieNotRenewedAfterSignOut()
395395
{
396396
var server = CreateServer(o =>
397397
{
398-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
398+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
399399
o.SlidingExpiration = false;
400400
o.Events = new CookieAuthenticationEvents
401401
{
@@ -431,7 +431,7 @@ public async Task CookieCanBeRenewedByValidator()
431431
{
432432
var server = CreateServer(o =>
433433
{
434-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
434+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
435435
o.SlidingExpiration = false;
436436
o.Events = new CookieAuthenticationEvents
437437
{
@@ -476,7 +476,7 @@ public async Task CookieCanBeRenewedByValidatorWithSlidingExpiry()
476476
{
477477
var server = CreateServer(o =>
478478
{
479-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
479+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
480480
o.Events = new CookieAuthenticationEvents
481481
{
482482
OnValidatePrincipal = ctx =>
@@ -520,7 +520,7 @@ public async Task CookieValidatorOnlyCalledOnce()
520520
{
521521
var server = CreateServer(o =>
522522
{
523-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
523+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
524524
o.SlidingExpiration = false;
525525
o.Events = new CookieAuthenticationEvents
526526
{
@@ -569,7 +569,7 @@ public async Task ShouldRenewUpdatesIssuedExpiredUtc(bool sliding)
569569
DateTimeOffset? lastExpiresDate = null;
570570
var server = CreateServer(o =>
571571
{
572-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
572+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
573573
o.SlidingExpiration = sliding;
574574
o.Events = new CookieAuthenticationEvents
575575
{
@@ -619,7 +619,7 @@ public async Task CookieExpirationCanBeOverridenInEvent()
619619
{
620620
var server = CreateServer(o =>
621621
{
622-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
622+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
623623
o.SlidingExpiration = false;
624624
o.Events = new CookieAuthenticationEvents()
625625
{
@@ -656,7 +656,7 @@ public async Task CookieIsRenewedWithSlidingExpiration()
656656
{
657657
var server = CreateServer(o =>
658658
{
659-
o.Cookie.Expiration = TimeSpan.FromMinutes(10);
659+
o.ExpireTimeSpan = TimeSpan.FromMinutes(10);
660660
o.SlidingExpiration = true;
661661
},
662662
SignInAsAlice);

0 commit comments

Comments
 (0)