我的cookie身份验证工作正常,但我想添加基本身份验证以用于Web API。我从其他地方开始遵循这些步骤来实现基本身份验证处理程序,但它似乎从未达到HandleAuthenticateAsync()
。
这是在startup()中设置的方式:
public void ConfigureServices(IServiceCollection services)
{
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Users/LogIn";
options.LogoutPath = "/Users/Logout";
options.AccessDeniedPath = "/Users/AccessDenied";
})
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
}
这是控制器:
[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = "BasicAuthentication")]
public class EmployeesController : ControllerBase
{
.....
}