gpt4 book ai didi

azure - 验证 Azure APIM 策略中的 JWT

转载 作者:行者123 更新时间:2023-12-01 23:55:31 25 4
gpt4 key购买 nike

在 Azure APIM 中,我尝试创建一个验证 JWT 的策略。无论我尝试什么,我总是收到“401:无效的 JWT”错误。有谁知道我做错了什么? (也许我没有使用正确的签名 key ?)

我的 Base64 编码安全 key 是 Zm9v

我在 jwt.io 创建示例 token ,因此我的授权 header 是:

Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.Bm8tu4m18oA96xwhBL8AV_4hRpIU6OrK5UaOmGqBEsk

这是我正在使用的政策:

<policies>
<inbound>
<base />
<validate-jwt
header-name="Authorization"
require-expiration-time="false"
require-scheme="Bearer"
>
<issuer-signing-keys>
<key>Zm9v</key>
</issuer-signing-keys>
</validate-jwt>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

HTTP 响应:

cache-control: private
content-length: 48
content-type: application/json
ocp-apim-trace-location: https://xxxxxxx
vary: Origin
{
"statusCode": 401,
"message": "Invalid JWT."
}

最佳答案

问题是我的 key 太小。

在 Azure 中测试 API 时,有一个“跟踪”选项卡,但缺少“出错时”部分。

enter image description here

您必须转到“消息”选项卡。有一个 ocp-apim-trace-location 将显示完整的跟踪。 enter image description here

事实证明我使用的 key 尺寸太小。只有24,至少需要128。 enter image description here

关于azure - 验证 Azure APIM 策略中的 JWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62805267/

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