Skip to content

Instantly share code, notes, and snippets.

@jarig
Created August 15, 2020 12:31
Show Gist options
  • Save jarig/27edf484aa17f0f9c672bba9b85d598b to your computer and use it in GitHub Desktop.
Save jarig/27edf484aa17f0f9c672bba9b85d598b to your computer and use it in GitHub Desktop.
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var builtConfig = config.Build();
var userAssignedId = builtConfig["UserAssignedId"];
AzureServiceTokenProvider azureServiceTokenProvider;
if (string.IsNullOrEmpty(userAssignedId))
{
azureServiceTokenProvider = new AzureServiceTokenProvider();
}
else
{
azureServiceTokenProvider = new AzureServiceTokenProvider($"RunAs=App;AppId={userAssignedId}");
}
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(
$"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
keyVaultClient,
new DefaultKeyVaultSecretManager());
})
.UseStartup<Startup>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment