I'm experimenting with Azure Key Vault for a hobby project. At first, I developed locally but now my db is in Azure. So I want this connectionstring safe in the Key Vault. I managed to do by the connected service option in visual studio. The connection is made and everything works as expected. Still, now I want in development to access the local db with the config value from the appsettings.json. I thought by wrapping the setup in the ConfigureAppConfiguration delegate in the program.cs like below would bypass Key Vault and goto local appsettings. But when running this code I still get the Key Vault secret value (and in debug the code is skipped (so IsDevelopment is true)
if (!context.HostingEnvironment.IsDevelopment())
{
var builtConfig = config.Build();
var keyVaultEndpoint = GetKeyVaultEndpoint();
if (!string.IsNullOrEmpty(keyVaultEndpoint))
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(
keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
}
}
So my questions are;
- Did anyone else experience this odd behaviour?
- How to deal properly with switching out key vault on local machine
context
? there is no variable in program.cs by default – Neville Nazerane