anastaciu
anastaciu

Reputation: 23832

How to find the Azure Function key used in a past request

When you make a request via Azure Function, there is a necessary host/master/function key that must be used in the request query, unless the function is anonymous.

The format is like

https://some_endpoint.com?code=the_key

Is there any way to find out the_key used in a given past request?

This was a request with a valid key, I could have logged it or otherwise keep it somewhere, but I didn't, and I need to find out what it was. Needless to say I have several keys for the same function.

Upvotes: 0

Views: 112

Answers (1)

RithwikBojja
RithwikBojja

Reputation: 11383

How to find the Azure Function key used in a given request

There is no way to find it AFAIK, but you can add code to log the key used to call function app as below:

[Function("Function1")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
    ri_lg.LogInformation("C# HTTP trigger function processed a request.");
    string rith_key = req.Query["code"];
    ri_lg.LogInformation($"Hello Rithwik, the key used is : {rith_key}");
    return new OkObjectResult("Welcome to Azure Functions!");
}

In C#:

req.Query["code"];

In Python:

req.params.get('code')

In js:

req.query.code;

Output:

enter image description here

enter image description here

You cannot get the name of the key, but can get the key used.

Upvotes: 0

Related Questions