Created
November 17, 2018 10:30
-
-
Save a-patel/10a760c48ee04fa8f1f2f32ce1693e29 to your computer and use it in GitHub Desktop.
Keeping Secrets Safe in ASP.NET Core with Azure Key Vault
This file contains hidden or 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) | |
| { | |
| 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