我正在寻找通过SignInManager实现ASP.net身份验证,但没有EntityFramework的身份。我已经使用SQLClient构建了自己的数据库层,并且只想创建使ASP.net身份验证起作用所需的任何调用。
我的代码如下(从Startup.cs执行):
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<OAuthAppDbContext>(opt => opt.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Cookies.ApplicationCookieAuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.CookieName = "oAuthInterop";
options.Cookies.ApplicationCookie.AutomaticChallenge = true;
options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
options.Cookies.ApplicationCookie.DataProtectionProvider = new DataProtectionProvider(new DirectoryInfo("d:\\development\\artefacts"),
configure =>
{
configure.SetApplicationName("TestAuthApp");
//configure.ProtectKeysWithCertificate("thumbprint");
});
})
.AddEntityFrameworkStores<OAuthAppDbContext, int>()
.AddDefaultTokenProviders();
并且我需要消除对Entity Framework的依赖(并调用我自己的db方法来收集用户详细信息)。有没有其他人在ASP.net核心中做过类似的事情?
在此先感谢您提供任何指导!:-)
至少,您将希望以您认为合适的任何方式实现IUserStore <ApplicationUser>,IUserPasswordStore <ApplicationUser>和IRoleStore <ApplicationUser>,并将它们注册到IServiceCollection中。您可能还需要实现一些其他接口来获取完整的标识功能(IUserClaimsStore,IUserPhoneNumberStore,IUserLockoutStore等-您可以在GitHub上找到整个列表)。
最后,不要忘记删除您的EF服务注册!
我已经把一个非常基本的内存例子在这里。它确实又快又脏,所以我不建议您从中汲取太多灵感。如果您真的想看到一个适当的实现,那么这里是实际EF版本的实现方式!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句