gpt4 book ai didi

azure - 如何调试承载错误="invalid_token"

转载 作者:行者123 更新时间:2023-12-02 07:51:48 27 4
gpt4 key购买 nike

我们正在构建一个具有 SPA 前端和 API 后端的应用程序。

我们使用 MSAL 身份验证库,前端和后端在 Azure AD 中注册为应用程序。

我们收到 HTTP 401 错误。

为了尝试调试该问题,我们从 SPA 应用程序中获取了 token ,并将其放入 jwt.io 中,看起来不错。我们还尝试使用不记名 token 从 postman 发送请求。还是同样的问题。

有没有办法找出 token 在什么情况下无效?

最佳答案

要获得 token 不被接受的一些线索的简单检查是在 AddJwtBearer 中将此标志设置为 true:

.AddJwtBearer(opt =>
{
opt.IncludeErrorDetails = true;
...

这样做,将在 WWW-Authenticate 响应 header 中包含拒绝的原因:

HTTP/1.1 401 Unauthorized
Date: Sun, 02 Aug 2020 11:19:06 GMT
WWW-Authenticate: Bearer error="invalid_token", error_description="The signature is invalid"

第二步是检查来自 AddJwtBearer 处理程序的日志。

为了补充这个答案,我写了一篇博客文章,详细介绍了这个主题: Troubleshooting JwtBearer authentication problems in ASP.NET Core

关于azure - 如何调试承载错误="invalid_token",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75336709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com