I have a local asp.net core 3.1 application that I want to set a secret in an Azure Key Vault. The following is the code I used from Microsoft:
string secretName = "xxSecret";
string keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME");
var kvUri = "https://" + keyVaultName + ".vault.azure.net";
var secretClient = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
string secretValue = "test";
secretClient.SetSecret(secretName, secretValue);
KeyVaultSecret secret = secretClient.GetSecret(secretName);
When I try to set a secret, I get the following error in Postman:
Azure.Identity.AuthenticationFailedException: DefaultAzureCredential authentication failed.
---> Azure.Identity.AuthenticationFailedException: SharedTokenCacheCredential authentication failed.
---> Microsoft.Identity.Client.MsalServiceException: AADSTS70002: The client does not exist or is not
enabled for consumers. If you are the application developer, configure a new application through the
App Registrations in the Azure Portal
I don't want to register this app, yet as I want to debug this locally. I'm guessing the issue is that I don't a correct Access Policy set up. How do I grant my local app access?
(Before I run the app locally, I authenticate to my Azure directory using Azure PowerShell. )