Hello @Casper Rubæk - Thanks for confirming in the private comments. Posting the below as a resolution to this thread:
Since APIM is in front of the Function App, and given how APIM maintains Client IP through context variable as follows: context.Request.IpAddress
The Client IP needs to be passed along to the Function App 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 your HttpTrigger function via HttpRequest
object as follows:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
....
var clientIP = req.Headers["X-Forwarded-Client-Ip"];
....
}
-------------------------------------------------------------------------------
Please consider contributing to MS Q&A by marking 'Accepted Answer' and ‘Upvoting’ as applicable.