使用AbpMvcAuthorize的自定义身份验证方案

时间:2018-08-22 14:43:47

标签: asp.net-core aspnetboilerplate

在特殊情况下,我无法使AbpMvcAuthorize属性正常工作。

我有一些自定义身份验证机制(带有自定义AuthenticationScheme),用于登录用户。 为此,我实现了AuthenticationHandler<MyCustomAuthenticationOptions>并覆盖了HandleAuthenticateAsync方法,并将其从Module-zero中注册到了AuthConfigurer.Configure方法中:

services.AddAuthentication(o => o.AddScheme("amx", b => b.HandlerType = typeof (MyCustomAuthenticationHandler)));

现在,如果我有这个:

[Authorize(AuthenticationSchemes = "amx")]
public string GetTest()
{
    return "OK";
}

并使用我的特殊amx标头发出请求,该请求正在运行,并且只有在指定该方法时我才能访问该方法。

如果我在做同样的事情:

[AbpMvcAuthorize(AuthenticationSchemes = "amx")]
public string GetTest()
{
    return "OK";
}

它不再工作,并且我得到401未经授权的结果,并且在调试模式下,我从不输入自定义AuthenticationHandler。 似乎AbpMvcAuthorize属性是在我的自定义AuthenticationHandler之前执行的,还是它没有读取AuthenticationScheme属性?

知道我做错什么了吗?

谢谢

1 个答案:

答案 0 :(得分:0)

我在他们的Github上问:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3778

并被告知目前无法实现此操作,因为AbpMvcAuthorize无法读取AuthenticationScheme属性。 我将尝试通过一些政策来实现它

相关问题