【问题标题】:JWT validation failure error in azure apimazure apim 中的 JWT 验证失败错误
【发布时间】:2020-01-02 08:21:03
【问题描述】:

我目前正在尝试使用以下文档实施 Oauth2.0 以保护 API

https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-protect-backend-with-aad

目前使用 azure apim 提供的 DEMO CONFERENCE API 来测试实现。

目前在开发者门户中的测试期间收到错误:

"message": "JWT 验证失败:声明值不匹配:aud=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx.."

通过解码和匹配将传递的令牌与声明值进行比较。

我有如下的 jwt 令牌验证策略

<inbound>
        <base />
        <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-expiration-time="false" require-signed-tokens="false">
            <openid-config url="https://login.microsoftonline.com/xxxxxxxxx-07c8-xxxxx-xxxx-xxxxxxxxx/.well-known/openid-configuration" />
            <required-claims>
                <claim name="aud" match="all" separator="-">
                    <value>xxxxxxxx-xxxxx-489e-a26e-xxxxxxxx</value>
                </claim>
            </required-claims>
        </validate-jwt>
</inbound>

【问题讨论】:

    标签: azure api oauth-2.0 jwt-auth apim


    【解决方案1】:

    首先,您需要验证您的 JWT 令牌。然后,当我们注册一个应用程序时,它会使用 V1 版本注册,并且访问令牌颁发者带有 sts url,如果我们尝试使用 V2 传递访问令牌,其失败的 V2 颁发者是login.microsoft.com

    所以修复是在清单文件"accessTokenAcceptedVersion": 2 中为 AD 中的注册应用程序。参考这个issue

    【讨论】:

    • 嗨,我为所有注册的应用程序更改了“accessTokenAcceptedVersion”:2,但我仍然看到错误为“JWT 验证失败:IDX10205:颁发者验证失败。颁发者:'login.microsoftonline.com/xxxxxxxxxxxxxxxxx/v2.0'。没有不匹配:validationParameters.ValidIssuer: '' 或 validationParameters.ValidIssuers: 'sts.windows.net/xxxxxxxxxxxxxxxxx/'.."
    • 你在apim中设置&lt;openid-config url="https://login.microsoftonline.com/xxxxxxxxx-07c8-xxxxx-xxxx-xxxxxxxxx/v2.0/.well-known/openid-configuration" /&gt;了吗?
    猜你喜欢
    • 2020-10-29
    • 2018-10-02
    • 2019-04-29
    • 1970-01-01
    • 2017-09-21
    • 2022-06-18
    • 1970-01-01
    相关资源
    最近更新 更多