Use Identity with existing bank

0

I'm migrating from a system to asp core, but the system currently has its login logic done in the procedure, my question is, is it possible to use only the authorization of Identity (Roles)? I found doing with existing database).

    
asked by anonymous 05.06.2018 / 21:41

1 answer

0

You can "force" authentication by searching the logged-in user with the rule you want, I have in particular developed a mobile app, and I have / created a default user to login every time the app tries to access my page and then "force" the authentication and after the authentication I redirect to the desired page. In my case it is a standard user already registered, but you can do the search by Role or go to Role and if everything is ok you do the command below. the name parameter is the user of my app that I pass, I do not check the password because it is the internal distribution app. The SignInManager class that is responsible for user authentication. I hope I have helped

Authentication is in the command: await _signInManager.SignInAsync (user, true);

My controller to authenticate my app.

public class AppLoginController : Controller
{
    private readonly ApplicationDbContext _context;
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly SignInManager<ApplicationUser> _signInManager;


    public AppLoginController(ApplicationDbContext context, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
    {
        _context = context;
        _userManager = userManager;
        _signInManager = signInManager;

    }

    [HttpGet]
    public async Task<IActionResult> Index(string name)
    {

        var user = await _userManager.FindByNameAsync(name);

        if (user != null)
        {

           await _signInManager.SignInAsync(user, true);

            return RedirectToAction("Index", "MeuController");

        }

        return RedirectToAction("Index", "Home");


    }
}
}
    
24.12.2018 / 01:43