2016-05-30 12 views
3

共有クッキー認証を実行する2つの.NETアプリがあります。 1つはASP.NET Core RC1アプリで、もう1つは従来の.NET 4.5.1アプリです。ASP.NET Core RC2と.NET 4.5.1のアプリケーション間の共有クッキー認証

これは、現在Startup.csConfiguration方法で時代遅れMicrosoft.Owin.Security.Cookies.Interopを使用して設定されています

これはうまく動作しますが、RC2のためのサポート方法ではありません。

RC2の共有Cookie認証を取得するにはどうすればいいですか?

+0

私はあなたがこれを理解できることを願っています。私はRC2から4.6.1にクッキーを渡す必要があるのと同じボートにいる。 – Matthew

答えて

3

https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharingSharing authentication cookie among Asp.Net Core 1 (MVC6) and MVC 5 applicationsを組み合わせると、私は実用的な解決策を思いつくことができました。これはそれまでの「正しい」方法であれば、私は考えているが、それは動作しますので、ここでは行く:

  1. はnugetパッケージアプリケーションの両方でMicrosoft.Owin.Security.Interop 1.0.0-rc2-finalを使用してください。

  2. DataProtectionProviderを使用して、暗号化キーのディスク上の同じ場所と同じ目的を指定して作成します。

  3. 両方のアプリケーションでcookie認証をowin方法で設定します。 Startup.csの設定方法では、

.NET 4.5.1:同じCookieNameTicketDataFormatを指定

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 
       }); 
関連する問題