Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Is The Alternate Of AuthenticationManager In .Net Core

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);

enter image description here

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 ?

like image 938
TAHA SULTAN TEMURI Avatar asked Oct 19 '25 04:10

TAHA SULTAN TEMURI


1 Answers

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.

like image 144
poke Avatar answered Oct 20 '25 19:10

poke