How to configure client API keys for Azure features

I want to create a C # Azure function using an http trigger. I want to protect it with an API key , provide a separate key for each client, and the function should provide client-specific data, so you need to determine who calls it.

Can I use the Azure function APIs to identify the client, for example. get the name of the key that was transferred? Or is there no way to find out in the azure function which key was used to authenticate the request?

If there was a method like GetApiKeyName() , I could check the key name for a list of clients in my database and return different data based on who called this function. for example, imagine that I have a sales tracking system and my function is /api/GetMonthlySales . If client 1 calls the function using their API key, they should receive monthly sales, and if client 2 calls it, they will have a different amount.

If this is not possible, this means that I need to provide additional authentication data to each client so that they can go to each function call, for example. customer id and secret key. But that defeats the goal of using Azure APIs, right?

A similar scenario would be if I wanted to charge clients when they called my function. How to determine which client calls my function?

+7
source share
2 answers

Rory

This, unfortunately, is not supported today. Authentication will be based on the key used, and you can cancel / renew individual client keys, but this information is not currently displayed in the functions.

There are some ways around the path, for example, mapping keys using the management API and matching the request key to identify the client, but they are cumbersome and inefficient.

I had a problem tracking this here and I just flagged it for sorting again to see if we will get it soon.

+6
source

I think the preferred way would be to use Api Management . In Api Management, you can configure your own authentication.

To prevent anyone other than Api Management from requesting your function, enable application service authentication / authorization for your functional application and only allow Api Management access to it.

0
source

Source: https://habr.com/ru/post/1264208/


All Articles