简体   繁体   English

如何在没有EntityFramework的情况下使用ASP.net Core 1“SignInManager”

[英]How to use ASP.net Core 1 “SignInManager” without EntityFramework

I'm looking to implement ASP.net authentication via the SignInManager but without the EntityFramework. 我想通过SignInManager实现ASP.net身份验证,但没有EntityFramework。 I have built my own database layer using SQLClient and want to just create whatever calls is needed in order to make ASP.net authentication work. 我已经使用SQLClient构建了自己的数据库层,并且想要创建所需的任何调用以使ASP.net身份验证工作。

The code I have is as follows (executed from the Startup.cs): 我的代码如下(从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();

and I need to remove the Entity Framework reliance (and call my own db methods for gathering user details). 我需要删除实体框架依赖(并调用我自己的数据库方法来收集用户详细信息)。 Has anyone else done something similar in ASP.net core? 有没有其他人在ASP.net核心做过类似的事情?

Thanks in advance for any pointers! 提前感谢任何指针! :-) :-)

At the very least, you'll want to implement IUserStore<ApplicationUser> , IUserPasswordStore<ApplicationUser> , and IRoleStore<ApplicationUser> in any way you see fit, and register them with your IServiceCollection. 至少,您需要以您认为合适的任何方式实现IUserStore <ApplicationUser>IUserPasswordStore <ApplicationUser>IRoleStore <ApplicationUser> ,并将它们与您的IServiceCollection一起注册。 There are a few other interfaces you might want to implement to get the full identity functionality (IUserClaimsStore, IUserPhoneNumberStore, IUserLockoutStore, etc. - you can find the whole list on GitHub ). 您可能需要实现一些其他接口来获取完整的身份功能(IUserClaimsStore,IUserPhoneNumberStore,IUserLockoutStore等 - 您可以在GitHub上找到整个列表 )。

Finally, don't forget to remove your EF service registrations! 最后,不要忘记删除您的EF服务注册!

I've put together a really basic in-memory example here . 我已经把一个非常基本的内存例子在这里 It's really quick and dirty, so I wouldn't recommend trying to take too much inspiration from it. 它非常快速和肮脏,所以我不建议尝试从中获取太多灵感。 If you really want to see a proper implementation, here is how the actual EF version is implemented ! 如果你真的想看到一个正确的实现, 这里是实际的EF版本的实现方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用EntityDataSource的情况下与Asp.Net一起使用EntityFramework? - How to Use EntityFramework with Asp.Net without using EntityDataSource? ASP.NET Core 2 导致 SignInManager 依赖项注入失败 - SignInManager dependency injection fails with ASP.NET Core 2 ASP.NET Core-发布应用程序后无法使用signInManager登录 - ASP.NET Core - Unable to signIn with signInManager when app is published 在 Asp.Net Core 3 Identity 中创建自定义 SignInManager - Creating a custom SignInManager in Asp.Net Core 3 Identity 将 SignInManager 和 AspNetUserManager 注入 Asp.Net Core 2 中的中间件 - Injecting SignInManager and AspNetUserManager to Middleware in Asp.Net Core 2 ASP .NET Core 标识登录管理器 - ASP .NET Core Identity SignInManager ASP Net Core SignInManager 未登录 - ASP Net Core SignInManager not signing in Asp.net core webapi entityframework如何查询distinct和not in - Asp.net core webapi entityframework how to query distinct and not in 如何在没有角色的情况下使用ASP.NET Core Identity? - How to use ASP.NET Core Identity without roles? Asp.Net Core - Identity SignInManager - 如何使用附加条件登录以便用户登录(例如:ClientId、UserName 和 Password)) - Asp.Net Core - Identity SignInManager - How to signIn with an additional conditions in order for users to login (ex: ClientId, UserName and Password))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM