Я пытаюсь создать метод, который будет настраивать IAppBuilder
в другой dll. Я экспериментирую с Identity и Owin, и я просто пытаюсь понять, как все работает.Настройка IAppBuilder за пределами проекта
Следующий код работает:
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("");
}
}
То, что я хотел сделать, это:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app = new AppBuilderService.BuildApp(app);
}
}
Код, который я пытался добавить в BuildApp
метод:
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;
}
Как вам может видеть, что код почти идентичен. Проблема, с которой я столкнулась, заключается в том, что CookieAuthenticationOptions.AuthenticationType
всегда красная, а визуальная студия не может распознать, и такая не может ее построить. Я не могу понять, какая ссылка отсутствует, поскольку я все-таки использую утверждения, которые у меня есть в Startup. VS также не делает никаких предложений.
Какую ссылку мне не хватает, чтобы сделать эту работу?
'DefaultAuthenticationTypes' является частью 'Microsoft.AspNet.Identity' найден в' Assembly Microsoft.AspNet.Identity.Core.dll, v2.0.0.0' – Nkosi
@Nkosi см. Я продолжал искать его в Owin https://msdn.microsoft.com/en-us /library/microsoft.owin.security.authenticationoptions (V = vs.113) .aspx – Bojan