I am working on .Net Core Project now I need AuthenticationManager for interface IAuthenticationManager
According to Microsoft this has obsolote.
To get ApplicationSignInManager I have this method
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);
}
}
This does work in Mvc project due to CreatePerOwinContext which is called using
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
But how can I activate this class in .Net Core?
Have also learned here that this CreateOwinContext is obsolote in .Net core here but can't figure out how to call create method of ApplicationSignInManager ?
AuthenticationManager
was a utility to perform authentication related actions through the HttpContext.Authentication
property. So you for example called HttpContext.Authentication.SignInAsync(…)
to sign in a user.
This access has been deprecated for quite a while now. There are now extensions methods directly on HttpContext
that serve this purpose:
HttpContext.AuthenticateAsync()
HttpContext.ChallengeAsync()
HttpContext.ForbidAsync()
HttpContext.GetTokenAsync()
HttpContext.SignInAsync()
HttpContext.SignOutAsync()
So now you just need access to the current HttpContext
and you can call the authentication actions directly, without needing the AuthenticationManager
indirection.
As for OWIN related things, note that ASP.NET Core does not use OWIN but created a completely new system. That one is based on OWIN, so you can find familiar things, but still fundamentally different. So you will need to get accustomed to the new authentication system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With