Created
June 2, 2020 13:35
-
-
Save manoj-choudhari-git/2cecfdaada557d0d1ab5ad8320b50226 to your computer and use it in GitHub Desktop.
App configurations for enabling key vault in .NET Core App
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 class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureAppConfiguration((context, config) => | |
{ | |
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()); | |
} | |
}) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.UseStartup<Startup>(); | |
}); | |
private static string GetKeyVaultEndpoint() => "https://<<your-key-vault>>.vault.azure.net"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment