ABP 在.Net 6 中遇到以下身份认证问题:
[Error]: Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
[WRN] ---------- RemoteServiceErrorInfo ----------
{
"code": "Volo.Authorization:010001",
"message": "Authorization failed! Given policy has not granted.",
"details": null,
"data": {},
"validationErrors": null
}
根据log分析 原因是鉴权失败,
但是TestApplicationService 的类没有添加 鉴权**[Authorize]**,
调用的三方的接口没有添加鉴权[Authorize],
最终发现是TestApplicationService 调用了一个有鉴权的Sevice导致的
结论:鉴权时 不仅仅是判断当前接口需要鉴权,还要判断该接口内部调用的接口是否有鉴权,如果有鉴权的话对该接口添加属性**[AllowAnonymous]**,来禁用身份验证.