简体   繁体   English

Azure API 管理 - 当产品不需要订阅时如何执行产品策略?

[英]Azure API Management - How to execute product policy when product does not require subscription?

I have a product published that does not requires a subscription.我发布了不需要订阅的产品。 The 4 APIs that compose it also does not.组成它的 4 个 API 也没有。 How can I define policies on a product level?如何在产品级别定义策略?
Such policies seem to work only when both the APIs AND the product require subscription AND the request is made using the product subscription key.此类策略似乎仅在 API产品都需要订阅并且使用产品订阅密钥发出请求时才有效。

Prerequisites:先决条件:

  1. API subscription switched off: API 订阅已关闭:

在此处输入图像描述

  1. Product subscription switched off:产品订阅已关闭:

在此处输入图像描述

  1. Product added to API:添加到 API 的产品:

在此处输入图像描述

  1. Product has policies defined, example:产品已定义策略,例如: 在此处输入图像描述

If above points are true, just call your API without Ocp-Apim-Subscription-Key header and APIM will automatically execute API and attached product policies.如果以上几点属实,只需在没有Ocp-Apim-Subscription-Key header 的情况下调用您的 API,APIM 将自动执行 API 和附加的产品策略。 If you provide Ocp-Apim-Subscription-Key with correct value, like for example administrator subscription key, APIM will only execute API policies.如果您为 Ocp-Apim-Subscription-Key 提供正确的值,例如管理员订阅密钥,APIM 将仅执行 API 策略。


To reduce the frustration it is important to understand policy order execution.为了减少挫败感,了解策略命令的执行很重要。 Read the whole article here but in short the order is:这里阅读整篇文章,但简而言之,顺序是:

  1. Global scope全球scope
  2. Product scope产品 scope
  3. API scope API scope
  4. Operation scope操作 scope

One last thing, if non subscription product is attached to non subscription API and its policies are executed automatically, you may wonder what happens if we add second open product to the API?最后一件事,如果非订阅产品附加到非订阅 API 并且其策略自动执行,您可能想知道如果我们将第二个开放产品添加到 API 会发生什么? Policies from which product will be executed?将从哪个产品执行策略? Turns out, this is not possible (what makes sense).事实证明,这是不可能的(这是有道理的)。 Attempting to add second open product will result in following error:尝试添加第二个打开的产品将导致以下错误:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM