Skip to content

Commit 4061b1b

Browse files
committed
Allow OWIN servers to register default ICookieManager instances
1 parent b286086 commit 4061b1b

File tree

15 files changed

+340
-11
lines changed

15 files changed

+340
-11
lines changed

src/Microsoft.Owin.Host.SystemWeb/OwinAppContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ internal void Initialize(Action<IAppBuilder> startup)
5959
builder.Properties[Constants.HostReferencedAssemblies] = new ReferencedAssembliesWrapper();
6060
builder.Properties[Constants.ServerCapabilitiesKey] = Capabilities;
6161
builder.Properties[Constants.SecurityDataProtectionProvider] = new MachineKeyDataProtectionProvider().ToOwinFunction();
62+
builder.SetDefaultCookieManager(new SystemWebCookieManager());
63+
builder.SetDefaultChunkingCookieManager(new SystemWebChunkingCookieManager());
6264
builder.SetLoggerFactory(new DiagnosticsLoggerFactory());
6365

6466
Capabilities[Constants.SendFileVersionKey] = Constants.SendFileVersion;

src/Microsoft.Owin.Security.Cookies/CookieAuthenticationMiddleware.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class CookieAuthenticationMiddleware : AuthenticationMiddleware<CookieAut
2727
public CookieAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, CookieAuthenticationOptions options)
2828
: base(next, options)
2929
{
30+
if (Options.CookieManager == null)
31+
{
32+
Options.CookieManager = app.GetDefaultChunkingCookieManager() ?? new ChunkingCookieManager();
33+
}
3034
if (Options.Provider == null)
3135
{
3236
Options.Provider = new CookieAuthenticationProvider();
@@ -46,10 +50,6 @@ public CookieAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, Cook
4650

4751
Options.TicketDataFormat = new TicketDataFormat(dataProtector);
4852
}
49-
if (Options.CookieManager == null)
50-
{
51-
Options.CookieManager = new ChunkingCookieManager();
52-
}
5353
}
5454

5555
/// <summary>

src/Microsoft.Owin.Security.Cookies/CookieAuthenticationOptions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics.CodeAnalysis;
66
using Microsoft.Owin.Infrastructure;
7+
using Owin;
78

89
namespace Microsoft.Owin.Security.Cookies
910
{
@@ -142,9 +143,11 @@ public string CookieName
142143

143144
/// <summary>
144145
/// The component used to get cookies from the request or set them on the response.
145-
///
146-
/// ChunkingCookieManager will be used by default.
147146
/// </summary>
147+
/// <remarks>
148+
/// The manager returned by <see cref="AppBuilderCookieExtensions.GetDefaultChunkingCookieManager(IAppBuilder)"/>
149+
/// (or a default <see cref="ChunkingCookieManager"/> instance) is used by default if no value is explicitly set.
150+
/// </remarks>
148151
public ICookieManager CookieManager { get; set; }
149152

150153
/// <summary>

src/Microsoft.Owin.Security.Facebook/FacebookAuthenticationMiddleware.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.CodeAnalysis;
66
using System.Globalization;
77
using System.Net.Http;
8+
using Microsoft.Owin.Infrastructure;
89
using Microsoft.Owin.Logging;
910
using Microsoft.Owin.Security.DataHandler;
1011
using Microsoft.Owin.Security.DataProtection;
@@ -45,6 +46,10 @@ public FacebookAuthenticationMiddleware(
4546

4647
_logger = app.CreateLogger<FacebookAuthenticationMiddleware>();
4748

49+
if (Options.CookieManager == null)
50+
{
51+
Options.CookieManager = app.GetDefaultCookieManager() ?? new CookieManager();
52+
}
4853
if (Options.Provider == null)
4954
{
5055
Options.Provider = new FacebookAuthenticationProvider();

src/Microsoft.Owin.Security.Facebook/FacebookAuthenticationOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public FacebookAuthenticationOptions()
3131
BackchannelTimeout = TimeSpan.FromSeconds(60);
3232
SendAppSecretProof = true;
3333
_fields = new HashSet<string>();
34-
CookieManager = new CookieManager();
3534

3635
AuthorizationEndpoint = Constants.AuthorizationEndpoint;
3736
TokenEndpoint = Constants.TokenEndpoint;

src/Microsoft.Owin.Security.Google/GoogleOAuth2AuthenticationMiddleware.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.CodeAnalysis;
66
using System.Globalization;
77
using System.Net.Http;
8+
using Microsoft.Owin.Infrastructure;
89
using Microsoft.Owin.Logging;
910
using Microsoft.Owin.Security.DataHandler;
1011
using Microsoft.Owin.Security.DataProtection;
@@ -47,6 +48,10 @@ public GoogleOAuth2AuthenticationMiddleware(
4748

4849
_logger = app.CreateLogger<GoogleOAuth2AuthenticationMiddleware>();
4950

51+
if (Options.CookieManager == null)
52+
{
53+
Options.CookieManager = app.GetDefaultCookieManager() ?? new CookieManager();
54+
}
5055
if (Options.Provider == null)
5156
{
5257
Options.Provider = new GoogleOAuth2AuthenticationProvider();

src/Microsoft.Owin.Security.Google/GoogleOAuth2AuthenticationOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public GoogleOAuth2AuthenticationOptions()
2929
AuthenticationMode = AuthenticationMode.Passive;
3030
Scope = new List<string>();
3131
BackchannelTimeout = TimeSpan.FromSeconds(60);
32-
CookieManager = new CookieManager();
3332

3433
AuthorizationEndpoint = Constants.AuthorizationEndpoint;
3534
TokenEndpoint = Constants.TokenEndpoint;

src/Microsoft.Owin.Security.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.CodeAnalysis;
66
using System.Globalization;
77
using System.Net.Http;
8+
using Microsoft.Owin.Infrastructure;
89
using Microsoft.Owin.Logging;
910
using Microsoft.Owin.Security.DataHandler;
1011
using Microsoft.Owin.Security.DataProtection;
@@ -45,6 +46,10 @@ public MicrosoftAccountAuthenticationMiddleware(
4546

4647
_logger = app.CreateLogger<MicrosoftAccountAuthenticationMiddleware>();
4748

49+
if (Options.CookieManager == null)
50+
{
51+
Options.CookieManager = app.GetDefaultCookieManager() ?? new CookieManager();
52+
}
4853
if (Options.Provider == null)
4954
{
5055
Options.Provider = new MicrosoftAccountAuthenticationProvider();

src/Microsoft.Owin.Security.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public MicrosoftAccountAuthenticationOptions() : base(Constants.DefaultAuthentic
2626
AuthenticationMode = AuthenticationMode.Passive;
2727
Scope = new List<string>();
2828
BackchannelTimeout = TimeSpan.FromSeconds(60);
29-
CookieManager = new CookieManager();
3029

3130
AuthorizationEndpoint = Constants.AuthorizationEndpoint;
3231
TokenEndpoint = Constants.TokenEndpoint;

src/Microsoft.Owin.Security.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net.Http;
77
using Microsoft.IdentityModel.Protocols;
88
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
9+
using Microsoft.Owin.Infrastructure;
910
using Microsoft.Owin.Logging;
1011
using Microsoft.Owin.Security.DataHandler;
1112
using Microsoft.Owin.Security.DataProtection;
@@ -38,6 +39,10 @@ public OpenIdConnectAuthenticationMiddleware(OwinMiddleware next, IAppBuilder ap
3839
Options.TokenValidationParameters.AuthenticationType = app.GetDefaultSignInAsAuthenticationType();
3940
}
4041

42+
if (Options.CookieManager == null)
43+
{
44+
Options.CookieManager = app.GetDefaultCookieManager() ?? new CookieManager();
45+
}
4146
if (Options.StateDataFormat == null)
4247
{
4348
var dataProtector = app.CreateDataProtector(

0 commit comments

Comments
 (0)