问题描述
我有一个WebAPI应用,正在使用第三方身份验证器(Firebase身份验证).
I have a WebAPI app which I'm using a 3rd party authenticator (Firebase authentication).
我可以进行身份验证,但是一旦用户登录到我的服务器,我想将凭据和用户数据保存到我的ASP.NET Identity表中.
I have the authentication working but once the user has logged into my server, I'd like to save credentials and user data into my ASP.NET Identity tables.
如果我在Startup.cs文件中调用此行,我似乎可以使用UserManager创建帐户
I seem to be able to use the UserManager to create accounts if I call this line in my Startup.cs file
services.AddIdentityCore<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
这使我可以在构造函数中添加UserManager,而无需添加所有登录页面和如果我调用AddIdentity()通常会获得的默认cookie身份验证方案
This allows me to add UserManager in my constructor without adding all the login pages and the default cookie authentication scheme I'd normally get if I called AddIdentity()
但是,当我像这样在构造函数中添加SignInManager时
However, when I add SignInManager in my constructor like this
public ValuesController(SignInManager<ApplicationUser> signInManager)
我似乎仍然收到此错误.
I still seem to be getting this error.
这似乎意味着AddIdentityCore没有添加SignInManager.如何将SignInManager添加为要进行依赖项注入的类?
This seems to mean that AddIdentityCore doesn't add SignInManager. How do I add SignInManager as a class to be dependency injected?
推荐答案
是的.如果您检查 Addidentity 和 AddIdentityCore ,您会发现AddIdentityCore
仅在没有SignInManager
That's true.If you check the source code of Addidentity and AddIdentityCore, you will find that AddIdentityCore
registers the UserManager
only without SignInManager
要在AddIdentityCore
中添加SignInManager
,您可以尝试:
To add SignInManager
with AddIdentityCore
, you could try:
IdentityBuilder builder = services.AddIdentityCore<ApplicationUser>();
builder = new IdentityBuilder(builder.UserType, builder.Services);
builder.AddEntityFrameworkStores<ApplicationDbContext>();
builder.AddSignInManager<SignInManager<ApplicationUser>>();
请参阅使用JWT的.Net Core 2.0 Web API-添加身份会破坏JWT身份验证
这篇关于如何依赖注入SignInManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!