我正在处理 .Net Core 项目,现在我需要 AuthenticationManager 接口(interface) IAuthenticationManager
根据微软this已经过时了。
要获取 ApplicationSignInManager,我有这个方法
private ApplicationSignInManager getSignInManager(ApplicationUserManager manager, IAuthenticationManager auth)
{
return new ApplicationSignInManager(manager, auth);
}
ApplicationSignInManager
public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
{
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
: base(userManager, authenticationManager)
{
}
public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
{
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
}
}
由于使用调用的 CreatePerOwinContext,这在 Mvc 项目中确实有效
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
但是如何在 .Net Core 中激活这个类呢?
在这里还了解到这个CreateOwinContext在.Net core中已经过时了here但不知道如何调用 ApplicationSignInManager 的创建方法?
最佳答案
AuthenticationManager
是一个通过 HttpContext.Authentication
执行身份验证相关操作的实用程序属性(property)。例如,您调用了 HttpContext.Authentication.SignInAsync(...)
来登录用户。
此访问权限已被弃用很长一段时间了。现在有extensions methods直接在用于此目的的 HttpContext
上:
-
HttpContext.AuthenticateAsync()
-
HttpContext.ChallengeAsync()
-
HttpContext.ForbidAsync()
-
HttpContext.GetTokenAsync()
-
HttpContext.SignInAsync()
-
HttpContext.SignOutAsync()
所以现在您只需要访问当前的 HttpContext
就可以直接调用身份验证操作,而不需要 AuthenticationManager
间接访问。
至于 OWIN 相关的东西,请注意 ASP.NET Core 不使用 OWIN 而是创建了一个全新的系统。那个是基于 OWIN 的,所以你可以找到熟悉的东西,但仍然有根本的不同。所以你需要习惯the new authentication system .
关于c# - .Net Core 中 AuthenticationManager 的替代方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58128901/