API Manager OAuth 服务器生成错误的受众声明

问题描述 投票:0回答:1

我已经根据 example 在 API Manager 中设置了后端应用程序、客户端应用程序和 OAuth 服务器。目前,OAuth 服务器和两个应用程序注册都设置为使用 v2 端点。目前 OAuth 服务器的

default scope
设置为
api://<backend-app client ID>
。这也是
audience
策略中
validate-jwt
标签的值。我的
required-claims
政策中没有
validate-jwt
。对于配置中的每个更改,我都会在测试控制台try-it模式中重新授权。

似乎无论我如何摆弄参数,开发者门户测试控制台收到的令牌的

aud
声明都是
"aud": "00000003-0000-0000-c000-000000000000",

我做错了什么?

编辑:

我意识到我必须将更改发布到开发人员门户。我还错误地认为我不需要 API 中的范围,因为我正在开发一个仅由守护程序应用程序调用的 API(使用应用程序角色)。在应用程序注册中设置测试范围、授予管理员同意、发布开发人员门户后,令牌携带正确的

aud
声明。然而我仍然得到 401,但假设这是一个不同的问题。

azure oauth azure-api-management
1个回答
0
投票

我已经添加了OAuth 2.0,如下所示-

enter image description here enter image description here enter image description here

在您注册的应用程序的授权中添加授权码授予流程 URL。

enter image description here

然后我在 API 的设置中启用了 OAuth 2.0。

enter image description here

添加了

validate-jwt
政策。

<policies>
    <inbound>
        <base />
        <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized" require-expiration-time="true" require-scheme="Bearer" require-signed-tokens="true">
            <openid-config url="https://login.microsoftonline.com/{tenant_Id}/v2.0/.well-known/openid-configuration" />
            <audiences>
                <audience>api://{client_Id}</audience>
            </audiences>
            <issuers>
                <issuer>https://sts.windows.net/{tenant_Id}/</issuer>
            </issuers>
            <required-claims>
                <claim name="aud" match="all">
                    <value>api://{client_Id}</value>
                </claim>
            </required-claims>
        </validate-jwt>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

我在门户中测试了此配置,然后在开发人员门户中尝试它,方法是在请求标头中手动提供不记名令牌,并且它有效。

enter image description here enter image description here

痕迹-

enter image description here

在转到开发者门户之前,请先尝试在门户中进行测试,如果出现任何错误,请检查 Trace。

© www.soinside.com 2019 - 2024. All rights reserved.