Skip to content

Instantly share code, notes, and snippets.

@a-patel
Created November 17, 2018 10:30
Show Gist options
  • Select an option

  • Save a-patel/10a760c48ee04fa8f1f2f32ce1693e29 to your computer and use it in GitHub Desktop.

Select an option

Save a-patel/10a760c48ee04fa8f1f2f32ce1693e29 to your computer and use it in GitHub Desktop.
Keeping Secrets Safe in ASP.NET Core with Azure Key Vault
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, builder) =>
{
var keyVaultEndpoint = GetKeyVaultEndpoint();
if (!string.IsNullOrEmpty(keyVaultEndpoint))
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
builder.AddAzureKeyVault(keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
}
})
.UseStartup<Startup>()
.Build();
private static string GetKeyVaultEndpoint() => Environment.GetEnvironmentVariable("KEYVAULT_ENDPOINT");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment