I want to create a C# Azure Function with http trigger. I want to secure it with an API Key, provide a separate key per customer, and the function should provide customer-specific data so needs to identify who is calling it.
Can I use Azure Function API Keys to identify the customer, e.g. get the name of the Key that has been passed? Or is there no way of knowing within the azure function which key was used to authenticate the request?
If there were a method like GetApiKeyName()
I could check the key name against a list of customers in my database and return different data based on who is calling the function. e.g. imagine I have a sales-tracking system and my function is /api/GetMonthlySales
. If customer 1 calls the function with their API key they should get their monthly sales and if customer 2 calls it they'd get a different amount.
If this isn't possible that means I need to give additional authentication data to each customer for them to pass to each function call, e.g. a customer Id and a secret Key. But this defeats the purpose of using Azure Functions API Keys, right?
A similar scenario would be if I want to charge customers when they call my function. How do I identify which customer is calling my function?
code
parameter and finding it in the DB. To provision new customers I need to both add them to Azure Function auth and then add them to my DB. Hopefully in future there'll be inbuilt support for this but it's not too cumbersome this way if you have few customers. – Rory