Created
June 14, 2020 05:43
-
-
Save wvanbesien/245b44a7f9ad7edbb36a3acba4fc1aa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureAppConfiguration((webBuilder) => { | |
var config = webBuilder.Build(); | |
var mode = (KeyVaultUsage)Enum.Parse(typeof(KeyVaultUsage), (config["Secrets:Mode"])); | |
if (mode != KeyVaultUsage.UseLocalSecretStore) | |
{ | |
KeyVaultOptions kvc = config.GetSection("Secrets").Get<KeyVaultOptions>(); | |
if (mode == KeyVaultUsage.UseClientSecret) | |
{ | |
webBuilder.AddAzureKeyVault(kvc.KeyVaultUri, kvc.ClientId, kvc.ClientSecret); | |
} | |
else //UseMsi | |
{ | |
var tokenProvider = new AzureServiceTokenProvider(); | |
//Create the Key Vault client | |
var kvClient = new KeyVaultClient((authority, resource, scope) => tokenProvider.KeyVaultTokenCallback(authority, resource, scope)); | |
//Add Key Vault to configuration pipeline | |
webBuilder.AddAzureKeyVault(kvc.KeyVaultUri, kvClient, new DefaultKeyVaultSecretManager()); | |
} | |
} | |
}) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseStartup<Startup>(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment