在 Azure API 管理上,我想使用从代理传递到服务的订阅 key 来识别调用背后的用户。
我能找到的唯一解决方案是获取所有订阅并过滤 primaryKey 或 secondaryKey 以最终找到使用此 REST API 的用户,但这会太长,因为我会有很多订阅。
https://xxx.management.azure-api.net/subscriptions?api-version=2014-02-14
当我激活跟踪以查看 Echo API 上的 API 管理如何处理消息时,我可以看到代理可以识别用户和产品:
{ "timestamp":"2014-08-19T15:20:06.7804622Z", "source":"request handler", "data":{ "configuration":{ "api":{ "from":"echo", "to":"http://echoapi.cloudapp.net/api" }, "operation":{ "method":"GET", "uriTemplate":"/resource" }, "user":{ "id":1, "groups":[ ] }, "product":{ "id":3 } } } },
我想在服务端获取这些信息来识别用户。
能否告诉我是否可以使用 Azure API Management REST API 从订阅 key 中获取用户?
谢谢,
强尼
最佳答案
您可以使用策略为每个请求检索有关用户的信息。它位于 API 发布者门户的 /Admin/Policies/
中。
<policies>
<inbound>
<set-header name="request-email" exists-action="override">
<value>@(context.User.Email)</value>
</set-header>
<set-header name="request-id" exists-action="override">
<value>@(context.User.Id)</value>
</set-header>
</inbound>
<backend>
<forward-request />
</backend>
<outbound />
见 https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetHTTPheader有关使用变量设置标题的更多信息。
关于rest - 如何使用 Azure API Management REST API 从订阅 key 中获取用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25388105/