You can "force" authentication by searching the logged in user with the rule you want, I particularly developed a mobile app and put/created a default user to log in every time the app tries to access my page and then "force" authentication and after authentication I redirect to desired page.
In my case it is already registered default user, but you can do the search by Scroll or pass the Scroll and if everything is all right you do the command below. the name parameter is the user of my app I pass, I do not check the password why it is internal distribution app. The Signinmanager class that is responsible for user authentication. I hope I helped
Authentication is in 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");
}
}
}
You want to log in to the "hand" and the system control the user with the roles?
– Barbetta