I am not sure if this is the way to go but here is what I am trying to achieve. I have two different types of controller action methods. And I need two different authentication method on each of them.
E.g. HomeController
[Authorize(AuthenticationSchemes = "Windows")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
ServiceController
[Authorize(AuthenticationSchemes = "BasicAuthentication")]
[Route("api/my-service")]
[ApiController]
public class ServiceController : ControllerBase
{
[Route("Evaluate")]
[HttpPost]
public EvaluateResponse Evaluate([FromBody]EvaluateRequest request)
{
//return something;
}
}
Startup.cs (ConfigureServices)
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
Startup.cs (Configure)
app.UseAuthentication();
Code for Basic authentication is implemented like mentioned here.
Now, if I am trying to invoke api/my-service/Evaluate it's still invoking windows authentication.
How can I implement two different authentication technique, one for HomeController and another for ServiceController?
HttpRequestto bypass windows authentication, validate based on basic authentication if it is redirected toServiceController?