How to get the User from the subscription-key using Azure API Management REST API?

前提是你 提交于 2021-02-06 13:56:49

问题


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.

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

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.

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

Thanks,

Johnny


回答1:


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 />

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




回答2:


Please refer to the discussion on MSDN forum



来源:https://stackoverflow.com/questions/25388105/how-to-get-the-user-from-the-subscription-key-using-azure-api-management-rest-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!