I'm building an API Server with ASP .NET Core. I needed to generate and manage API Keys. So i searched about that, and i found 'Azure Key Vaults'. I thought it might be a solution, but it was paid service. So i wondered what is general way to generate and manage API Keys in ASP .NET Core. I will be thankful if you help me.
-
Check out this tutorial for creating ApiKey Authentication youtu.be/Zo3T_See7iIspaleet– spaleet2022-05-03 08:55:33 +00:00Commented May 3, 2022 at 8:55
-
Azure Key Vault is used to store API keys and other credentials, not generate them. What are you trying to do? Securely storing credentials is completely different from generating and managing API keys for clients/customers of your service.Panagiotis Kanavos– Panagiotis Kanavos2022-05-03 09:35:59 +00:00Commented May 3, 2022 at 9:35
-
@PanagiotisKanavos I think i wrote a little bit confusing words. I'm sorry about that. I know the usage of Azure Key Vault too. I meant "managing" == "generating" + "storing" + etc. So i wanted to know how to generate api keys and how to store api keys.hangooksaram– hangooksaram2022-05-04 01:45:17 +00:00Commented May 4, 2022 at 1:45
-
@hangooksaram, do you mean you have an API for which you want to generate keys for its users? If yes, please refer to Simple and secure custom API Keys using ASP.NET Core. Regarding storing the keys, I have informed some options in my answer. Please see my updated answer.Deepak-MSFT– Deepak-MSFT2022-05-04 05:16:07 +00:00Commented May 4, 2022 at 5:16
-
@Deepak-MSFT Yes, I checked you answer and i checked the reference in your comment too. Your answer was very helpful. Thank you.hangooksaram– hangooksaram2022-05-04 07:45:08 +00:00Commented May 4, 2022 at 7:45
2 Answers
It depends on your logic and how you would like the API key to generate if you are doing it by yourself.
You could refer to Simple and secure custom API Keys using ASP.NET Core to generate API keys.
If you are consuming the APIs in your project then those APIs will provide you with the keys.
Further, It looks like you are concerned about storing/managing the API keys.
In the Development environment, you could try to store it in the AppSettings.json, or you could store it using the Environment variables or you could try to use Secret Manager.
It is quite risky and not recommended to rely on these methods to store the API keys for the production environment. For the production environment, I would suggest you store the API keys in the Azure Key Vault. I understand that you need to pay to use it but it is the recommended approach to securely store the API keys.
References:
Comments
Azure Key Vault is great but it has some drawbacks. It costs, isn't that fast and it can become a burden with lots of Keys. There's an AZ303 question about making multiple key vaults to scale.
You know the AppConfig has a FREE tier and you can store your API keys in there: https://azure.microsoft.com/en-us/pricing/details/app-configuration/
For Database Connection Strings I'd still use Azure Key Vault, for API keys I wouldn't worry about storing in Azure App Config if there's only a few dozen and its not for externally used services.