https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharingとSharing authentication cookie among Asp.Net Core 1 (MVC6) and MVC 5 applicationsを組み合わせると、私は実用的な解決策を思いつくことができました。これはそれまでの「正しい」方法であれば、私は考えているが、それは動作しますので、ここでは行く:
はnugetパッケージアプリケーションの両方でMicrosoft.Owin.Security.Interop 1.0.0-rc2-final
を使用してください。
DataProtectionProvider
を使用して、暗号化キーのディスク上の同じ場所と同じ目的を指定して作成します。
両方のアプリケーションでcookie認証をowin方法で設定します。 Startup.cs
の設定方法では、
.NET 4.5.1:同じCookieName
とTicketDataFormat
を指定
var authenticationType = "Cookies";
var cookieName = "myCookieName";
var cookieEncryptionKeyPath= "C:/mypath";
var dataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
var dataProtector = dataProtectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
var ticketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector));
app.SetDefaultSignInAsAuthenticationType(authenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = authenticationType,
CookieName = cookieName,
TicketDataFormat = ticketDataFormat
});
.NETコアRC2をStartup.cs
の設定方法に:
var authenticationType = "Cookies";
var cookieName = "myCookieName";
var cookieEncryptionKeyPath= "C:/mypath";
var protectionProvider = DataProtectionProvider.Create(new DirectoryInfo(cookieEncryptionKeyPath));
var dataProtector = protectionProvider.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", authenticationType, "v2");
var ticketFormat = new TicketDataFormat(dataProtector);
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
CookieName = options.CookieName,
CookieDomain = options.CookieDomain,
TicketDataFormat = ticketFormat
});
私はあなたがこれを理解できることを願っています。私はRC2から4.6.1にクッキーを渡す必要があるのと同じボートにいる。 – Matthew