From a94aedcc1d47ffecc2de9985b071f75fbcfbd2b5 Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Mon, 10 Nov 2025 16:59:19 -0800 Subject: [PATCH 1/2] Add wrapper for SetDataProtectionProvider --- .../AuthRemoteIdentityCore/Program.cs | 2 ++ .../AuthRemoteIdentityFramework/Web.config | 6 +++++ samples/Directory.Packages.props | 2 +- src/Directory.Packages.props | 1 + .../AppBuilderExtensions.cs | 26 +++++++++++++++++++ ...t.AspNetCore.SystemWebAdapters.Owin.csproj | 1 + 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters.Owin/AppBuilderExtensions.cs diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs index 6293a5aa1..1dac16587 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs @@ -20,6 +20,7 @@ using Microsoft.Owin; using Microsoft.Owin.Extensions; using Microsoft.Owin.Security.Cookies; +using Microsoft.Owin.Security.DataProtection; using Microsoft.Owin.Security.Interop; using MvcApp; using MvcApp.Models; @@ -60,6 +61,7 @@ // Must match the Scheme name on the MvcCoreApp, i.e. IdentityConstants.ApplicationScheme "SharedCookie", "v2"); + app.SetDataProtectionProvider(services.GetDataProtectionProvider()); app.UseCookieAuthentication(new CookieAuthenticationOptions { diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config index e783e993d..ac6163834 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityFramework/Web.config @@ -241,6 +241,12 @@ + + + + + + diff --git a/samples/Directory.Packages.props b/samples/Directory.Packages.props index c1dd6c1d6..517c782c7 100644 --- a/samples/Directory.Packages.props +++ b/samples/Directory.Packages.props @@ -45,7 +45,7 @@ - + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 17e40277b..d0842cf61 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -20,6 +20,7 @@ + diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/AppBuilderExtensions.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/AppBuilderExtensions.cs new file mode 100644 index 000000000..e5d438ec1 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/AppBuilderExtensions.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.AspNetCore.DataProtection; +using Microsoft.Owin.Security.Interop; +using Owin; + +using AspNetCoreDataProtectionProvider = Microsoft.AspNetCore.DataProtection.IDataProtectionProvider; + +namespace Microsoft.Owin.Security.DataProtection; + +public static class AppBuilderDataProtectionExtensions +{ + public static void SetDataProtectionProvider(this IAppBuilder app, AspNetCoreDataProtectionProvider dataProtectionProvider) + { + ArgumentNullException.ThrowIfNull(app); + ArgumentNullException.ThrowIfNull(dataProtectionProvider); + + app.SetDataProtectionProvider(new DataProtectionProviderShim(dataProtectionProvider)); + } + + private sealed class DataProtectionProviderShim(AspNetCoreDataProtectionProvider other) : IDataProtectionProvider + { + public IDataProtector Create(params string[] purposes) => new DataProtectorShim(other.CreateProtector(purposes)); + } +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/Microsoft.AspNetCore.SystemWebAdapters.Owin.csproj b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/Microsoft.AspNetCore.SystemWebAdapters.Owin.csproj index d432c6fc2..9fdbef551 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/Microsoft.AspNetCore.SystemWebAdapters.Owin.csproj +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/Microsoft.AspNetCore.SystemWebAdapters.Owin.csproj @@ -10,6 +10,7 @@ + From 1c8f187111596b1e36cb6ba5f35a4f9a159ec87d Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Tue, 11 Nov 2025 11:07:45 -0800 Subject: [PATCH 2/2] run as default --- .../AuthRemoteIdentityCore/Program.cs | 1 - .../OwinBuilder.cs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs index 1dac16587..e4aa36810 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs @@ -61,7 +61,6 @@ // Must match the Scheme name on the MvcCoreApp, i.e. IdentityConstants.ApplicationScheme "SharedCookie", "v2"); - app.SetDataProtectionProvider(services.GetDataProtectionProvider()); app.UseCookieAuthentication(new CookieAuthenticationOptions { diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/OwinBuilder.cs b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/OwinBuilder.cs index 40ef76fb2..92a00baa9 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/OwinBuilder.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters.Owin/OwinBuilder.cs @@ -1,11 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Owin.Builder; using Microsoft.Owin.BuilderProperties; +using Microsoft.Owin.Security.DataProtection; using Owin; namespace Microsoft.AspNetCore.SystemWebAdapters; @@ -25,8 +27,18 @@ public static AppFunc Build(AppFunc defaultApp, Action() is { } dataProtectionProvider) + { + app.SetDataProtectionProvider(dataProtectionProvider); + } + } }