【发布时间】:2021-11-06 03:41:09
【问题描述】:
我的项目中有两种认证方式,第一种是通过JWT,第二种还是会实现。
如果 JWT 身份验证出错,我需要调用第二种身份验证,如果成功,则继续调用控制器。
但是,OnAuthenticationFailed 事件的处理不起作用。
如何在 OnAuthenticationFailed 事件中强制成功?
没有用
services.AddAuthentication(BearerAuthenticationDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = configuration.GetSection("AuthenticationConfiguration").GetValue<string>("Authority");
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateAudience = false
};
options.Events = new JwtBearerEvents()
{
OnAuthenticationFailed = c =>
{
//here a second authentication will be implemented
//(if secondauthentication.IsSucess)
c.Exception = null;
c.Success();
return Task.CompletedTask;
}
};
});
【问题讨论】:
标签: c# asp.net-core jwt asp.net-core-webapi middleware