繁体   English   中英

ASP.NET 核心 JWT 验证安全 webAPI [授权] 属性错误 401 未经授权

[英]ASP.NET Core JWT Authentication to secure webAPI [Authorize] attribute Error 401 Unauthorized

我开发了 API POST 并且它工作正常,但是当我添加 [Authorize] 属性时,我在 postman 中得到 401 Unauthorized 即使我在 Z099FB995346F31C749F6E40DB0F39E

 [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
           
            [HttpPost]
            
            public async Task<ActionResult> Post([FromBody] CViewModel cVM)
            {
    // to do
            }

I just want to secure my API with JWT TOKEN, API authentication work correctly and generate a token but I can't figure why when I added [Authorize] attribute I got Error 401 Unauthorized in my POST API.

谢谢!

添加[Authorize]时,只有携带令牌才能成功访问此操作。 一种可能性是 url 与这条路线无关。 但更重要的原因是您没有正确配置登录路径,或者登录路径不存在。 所以你可以在启动时检查配置。

问题是我在启动时使用了不同的密钥并生成令牌方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM