diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityCore/Program.cs index 6293a5aa1..e4aa36810 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; 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 @@ + 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); + } + } }