4

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 ?

TAHA SULTAN TEMURI
  • 4,031
  • 2
  • 40
  • 66

1 Answers1

9

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:

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.

poke
  • 369,085
  • 72
  • 557
  • 602