How to Idenify/filter which client(multiple Mobile & web requests) is calling to an API hosted on Azure(App Service possibly) ?

SidK 21 Reputation points
2022-08-19T11:53:59.613+00:00

This is about reusable API. Is this achievable through API Management or some other service like Front Door etc.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,741 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,421 Reputation points
    2022-08-23T07:13:41.897+00:00

    Hi @SidK ,

    Thanks for reaching out to Q&A.

    If you integrate APIM in front of app service, APIM maintains Client IP through context variable as follows: context.Request.IpAddress

    The Client IP needs to be passed along to the App service by way of defining a header via a small policy snippet:

    <set-header name="X-Forwarded-Client-Ip" exists-action="override">
    <value>@(context.Request.IpAddress)</value>
    </set-header>

    The corresponding value then can be accessed in the app service code HttpRequest object as follows:

    public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
    {
    ....

    var clientIP = req.Headers["X-Forwarded-Client-Ip"];  
    ....  
    

    }

    I hope using the client ip you will be able to figure out the client app. Feel free to reach out to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.