我希望通过 SignInManager 但没有 EntityFramework 来实现 ASP.net 身份验证。我已经使用 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 依赖(并调用我自己的数据库方法来收集用户详细信息)。有没有其他人在 ASP.net Core 中做过类似的事情?
在此先感谢您的指点! :-)
最佳答案
至少,您需要实现 IUserStore<ApplicationUser> , IUserPasswordStore<ApplicationUser> , 和 IRoleStore<ApplicationUser>以您认为合适的任何方式,并将它们注册到您的 IServiceCollection。您可能希望实现其他一些接口(interface)以获得完整的身份功能(IUserClaimsStore、IUserPhoneNumberStore、IUserLockoutStore 等 - you can find the whole list on GitHub)。
最后,不要忘记删除您的 EF 服务注册!
我整理了一个非常基本的内存示例 here .它真的又快又脏,所以我不建议尝试从中获取太多灵感。如果你真的想看到一个正确的实现,here is how the actual EF version is implemented !
关于c# - 如何在没有 EntityFramework 的情况下使用 ASP.net Core 1 "SignInManager",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794285/