【发布时间】:2021-05-20 13:21:31
【问题描述】:
我开发 API POST 并且它工作正常,但是当我添加 [Authorize] 属性时,即使我在标题中添加正确的令牌,邮递员也会收到 401 Unauthorized
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpPost]
public async Task<ActionResult> Post([FromBody] CViewModel cVM)
{
// to do
}
我只想使用 JWT TOKEN 保护我的 API, API 身份验证正常工作并生成令牌,但我不知道为什么添加 [Authorize] 属性我得到错误 401 Unauthorized 在我的 POST API 中。
谢谢!
【问题讨论】:
-
谢谢,但没有,当我更改为 [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] 我得到 401 Unauthorized
标签: asp.net-core asp.net-web-api jwt token authorize-attribute