2016-08-05 10 views
1

Ich versuche, eine Methode zu erstellen, die IAppBuilder in einer anderen DLL konfigurieren wird. Ich experimentiere mit Identity und Owin und ich versuche nur zu verstehen, wie die Dinge funktionieren.Konfigurieren Sie IAppBuilder außerhalb des Projekts

Der folgende Code funktioniert:

public partial class Startup 
{ 
    public void ConfigureAuth(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Login"), 
      Provider = new CookieAuthenticationProvider 
      { 
       OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserService, User>(
        TimeSpan.FromMinutes(30), (manager, user) => user.GenerateUserIdentityAsync(manager)) 
      } 
     });    
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 
     app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 
     app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); 

     app.UseTwitterAuthentication(
      consumerKey: "", 
      consumerSecret: "" 
      ); 

     app.UseFacebookAuthentication(
      appId: "", 
      appSecret: "" 
     ); 

     app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() 
     { 
      ClientId = "", 
      ClientSecret = "" 
     }); 

     app.UseSteamAuthentication(""); 
    } 
} 

Was ich dies tun wollte:

public partial class Startup 
{ 
    public void ConfigureAuth(IAppBuilder app) 
    { 
     app = new AppBuilderService.BuildApp(app); 
    } 
} 

Der Code, den ich versucht, indem zu BuildApp Methode:

public class AppBuilderService 
{ 
    public IAppBuilder BuildApp(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Login"), 
      Provider = new CookieAuthenticationProvider 
      { 
       OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserService, User>(
        TimeSpan.FromMinutes(30), (manager, user) => user.GenerateUserIdentityAsync(manager)) 
      } 
     });    
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 
     app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 
     app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); 

     app.UseTwitterAuthentication(
      consumerKey: "", 
      consumerSecret: "" 
      ); 

     app.UseFacebookAuthentication(
      appId: "", 
      appSecret: "" 
     ); 

     app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() 
     { 
      ClientId = "", 
      ClientSecret = "" 
     }); 

     app.UseSteamAuthentication(""); 
    } 

    return app; 
} 

Wie Sie kann sehen, dass der Code fast identisch ist. Das Problem, das ich habe, ist, dass CookieAuthenticationOptions.AuthenticationType immer rot ist und Visual Studio nicht erkennen kann und so kann es nicht bauen. Ich kann anscheinend nicht herausfinden, welche Referenz fehlt, da ich dieselben Anweisungen verwende, die ich im Startup habe. VS macht auch keine Vorschläge.

Welche Referenz fehlt mir, um diese Arbeit zu machen?

+0

'DefaultAuthenticationTypes' ist Teil zugeordnet aufzuzählen 'Microsoft.AspNet.Identity' gefunden in' Assembly Microsoft.AspNet.Identity.Core.dll, v2.0.0.0' – Nkosi

+0

@Nkosi siehe ich habe es in Owin https://msdn.microsoft.com/en-us gesucht /library/microsoft.owin.security.authenticationoptions (v = vs.113) .aspx – Bojan

Antwort

0

DefaultAuthenticationTypes gehört Microsoft.AspNet.Identity in Assembly Microsoft.AspNet.Identity.Core.dll, v2.0.0.0 gefunden

es in erster Linie von OWIN verwendet wird, um die Standard-Authentifizierungstypen mit Microsoft ASP.NET Identität 2,0

DefaultAuthenticationTypes Class

Verwandte Themen