Azure APIM 订阅密钥策略不起作用

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

我正在尝试找出azure apim,我主要使用它来为域名创建azure功能,所有端点都是面向公众的,并且都使用OAuth进行身份验证。

但是我对订阅密钥有疑问,我的主要问题是需要它们吗?如果我进入设置并选择所需的订阅密钥为 false,我的 api 就可以工作,但我无法让它工作,我在入站策略上添加策略来添加它

<inbound>
    <base />
    <set-header name="Ocp-Apim-Subscription-Key" exists-action="override">
        <value>{{subscription-key}}</value>
    </set-header>
</inbound>

那么我需要它们吗? (我想让政策发挥作用,不管只是因为),任何建议都会被采纳

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

如果您在设置中禁用了需要订阅密钥选项,则在调用任何请求时无需传递

Ocp-Apim-Subscription-Key

当您想要获取

Named value

 参数 
subscription-key 的值时,正在使用 {{subscription-key}} 格式。

在 APIM 中,标头名称

Ocp-Apim-Subscription-Key
用于主订阅密钥,如下所示

enter image description here

  • 在设置中禁用需要订阅密钥选项后,在门户中测试 API 操作时,默认情况下仍会在请求标头中传递
    Ocp-Apim-Subscription-Key
    。您可以使用以下策略验证它并检查跟踪。
<policies>
    <inbound>
        <base />
        <check-header name="Ocp-Apim-Subscription-Key" failed-check-httpcode="200" failed-check-error-message="Ignore subscription key" />
    </inbound>
</policies>
  • 但是,如果您在门户之外进行测试(例如在邮递员中,当所需的订阅密钥设置为 false 时),则不需要在请求标头中显式传递
    Ocp-Apim-Subscription-Key
    键。如果启用,则您需要在请求标头中提供密钥。

enter image description here

  • 当所需的订阅密钥设置为 false 时,您可以使用以下策略来传递
    Ocp-Apim-Subscription-Key
    键值。
<policies>
    <inbound>
        <base />
        <set-header name="hasSubscriptionKey" exists-action="override">
            <value>@(context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key", ""))</value>
        </set-header>
    </inbound>
</policies>

追踪-

enter image description here

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