如何使用Azure API管理REST API从订阅密钥中获取用户? [英] How to get the User from the subscription-key using Azure API Management REST API?

查看:85
本文介绍了如何使用Azure API管理REST API从订阅密钥中获取用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure API管理上,我想使用从代理传递到服务的订阅密钥来识别呼叫背后的用户.

On Azure API Management, I would like to use the subscription-key passed from the proxy to the service to identify the user behind the call.

我能找到的唯一解决方案是获取所有子脚本并在primaryKey或secondaryKey上进行过滤,以最终找到使用此REST API的用户,但这将太长了,因为我将有很多订阅.

The only solution I can find is to get all subcriptions and filter on the primaryKey or the secondaryKey to finaly find the user with this REST API but it will be too long because I will have a lot of subscriptions.

https://xxx.management.azure-api.net/subscriptions?api-version=2014-02-14

当我激活跟踪以查看Echo API上的API管理如何处理消息时,我可以看到代理可以识别用户和产品:

When I activate the trace to see how the message is handled by the API mangement on the Echo API, I can see that the proxy can identify the user and the product :


    {
    "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
    }
    }
    }
    },

我想在服务端获取此信息以识别用户.

I would like to get this information in the service side to identify the user.

您能否告诉我是否可以使用Azure API Management REST API从订阅密钥中获取用户?

Could you tell me if it's possible to get the user from the subscription-key using Azure API Management REST API ?

谢谢

Johnny

推荐答案

您可以使用策略为每个请求检索有关用户的信息.它位于API发布者门户的/Admin/Policies/中.

You can retrieve information regarding the user for each request utilizing policies. This is located in /Admin/Policies/ in the API publisher portal.

<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://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetHTTPheader 有关设置带有变量的标头的更多信息.

See https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetHTTPheader for more info regarding setting headers with variables.

这篇关于如何使用Azure API管理REST API从订阅密钥中获取用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆