自定义身份验证方案授权失败 - asp.net-core 3.0
authorization failing with custom authentication scheme - asp.net-core 3.0
我正在使用:
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
});
在 ConfigureServices
中注册自定义身份验证方案。
当我尝试在我的控制器中使用此方案时:
[Authorize(Roles = "admin", AuthenticationSchemes = "custom")]
public ActionResult Index()
{
return View();
}
它只是将我重定向到登录页面,即使用户已登录并且角色正确。
现在,如果我将 AuthenticationScheme
更改为:
[Authorize(Roles = "admin", AuthenticationSchemes = "Identity.Application")]
public ActionResult Index()
{
return View();
}
一切正常,用户已获得授权。
我在自定义身份验证方案的设置中是否遗漏了什么?我如何让我的自定义身份验证方案以与 Identity.Application
相同的方式工作?
谢谢
ps: 我正在使用 asp.net 核心 3.0 预览版 9
设置options.ForwardAuthenticate = "Identity.Application";
似乎解决了这个问题:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
options.AccessDeniedPath= "/admin/in";
options.ForwardAuthenticate = "Identity.Application";
});
}
这确实应该记录在案
我正在使用:
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
});
在 ConfigureServices
中注册自定义身份验证方案。
当我尝试在我的控制器中使用此方案时:
[Authorize(Roles = "admin", AuthenticationSchemes = "custom")]
public ActionResult Index()
{
return View();
}
它只是将我重定向到登录页面,即使用户已登录并且角色正确。
现在,如果我将 AuthenticationScheme
更改为:
[Authorize(Roles = "admin", AuthenticationSchemes = "Identity.Application")]
public ActionResult Index()
{
return View();
}
一切正常,用户已获得授权。
我在自定义身份验证方案的设置中是否遗漏了什么?我如何让我的自定义身份验证方案以与 Identity.Application
相同的方式工作?
谢谢
ps: 我正在使用 asp.net 核心 3.0 预览版 9
设置options.ForwardAuthenticate = "Identity.Application";
似乎解决了这个问题:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication().AddCookie("custom", options=> {
options.LoginPath = "/admin/in";
options.LogoutPath = "/admin/out";
options.AccessDeniedPath= "/admin/in";
options.ForwardAuthenticate = "Identity.Application";
});
}
这确实应该记录在案