Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Created June 10, 2019 04:17
Show Gist options
  • Save kasunkv/65e32c83d77b088ee5230a533e793325 to your computer and use it in GitHub Desktop.
Save kasunkv/65e32c83d77b088ee5230a533e793325 to your computer and use it in GitHub Desktop.
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, config) => {
// Fetch app settings from Azure Key Vault if its in production mode.
if (ctx.HostingEnvironment.IsProduction())
{
var configRoot = config.Build();
var tokenProvider = new AzureServiceTokenProvider();
config.AddAzureKeyVault(
$"https://{configRoot["AppSettings:KeyVaultName"]}.vault.azure.net/",
new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback)),
new DefaultKeyVaultSecretManager());
}
})
.UseStartup<Startup>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment