添加JWT认证失败时的自定义响应处理
This commit is contained in:
parent
5d9da6360a
commit
0589c29e5d
@ -83,6 +83,17 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
IssuerSigningKey = secKey
|
IssuerSigningKey = secKey
|
||||||
};
|
};
|
||||||
|
x.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnChallenge = context =>
|
||||||
|
{
|
||||||
|
context.HandleResponse();
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
return context.Response.WriteAsJsonAsync(new ReturnTemplate(401,"你提供了一个错误的Token,所以我们无法验证你的身份,唔......",null));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
})
|
})
|
||||||
.AddCookie("Identity.External").AddCookie("Identity.Application");
|
.AddCookie("Identity.External").AddCookie("Identity.Application");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user