2016-05-30 2 views
3

Wir haben zwei .NET-Anwendungen mit gemeinsamer Cookie-Authentifizierung. Eine ist eine ASP.NET Core RC1 App und die andere ist eine klassische .NET 4.5.1 App.Geteilte Cookie-Authentifizierung zwischen ASP.NET Core RC2 und .NET 4.5.1-Anwendungen

wird mit dem veralteten Microsoft.Owin.Security.Cookies.Interop im Configuration Methode von Startup.cs eingerichtet Dieses derzeit:

Dies funktioniert gut, ist aber nicht für RC2 unterstützte Methode.

Wie können wir mit der gemeinsamen Cookie-Authentifizierung für RC2 loslegen?

+0

Ich hoffe, du kannst das herausfinden. Ich bin im gleichen Boot und muss Cookies von RC2 an 4.6.1 weitergeben. – Matthew

Antwort

3

Kombinieren https://github.com/GrabYourPitchforks/aspnet5-samples/tree/dev/CookieSharing und Sharing authentication cookie among Asp.Net Core 1 (MVC6) and MVC 5 applications Ich war in der Lage, eine funktionierende Lösung zu finden. Ich habe keine Ahnung, ob dies die „richtige“ Art und Weise ist es, aber es funktioniert, so geht es hier:

  1. das nuget-Paket Microsoft.Owin.Security.Interop 1.0.0-rc2-final in beiden Anwendungen verwenden.

  2. Erstellen Sie eine TicketDataFormat mit DataProtectionProvider Angabe der gleichen Speicherort auf der Festplatte für die Verschlüsselungsschlüssel, sowie den gleichen Zweck.

  3. Konfigurieren Sie die Cookie-Authentifizierung in beiden Anwendungen. Geben Sie den gleichen CookieName und TicketDataFormat:

.NET 4.5.1 im Configure Methode Startup.cs:

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 CORE RC2 in dem Configure-Methode von 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 
       }); 
Verwandte Themen