Created
February 3, 2020 18:12
-
-
Save kasunkv/df739d22bdf604fc3cbf017e7751abb7 to your computer and use it in GitHub Desktop.
Configure Azure Key Vault to work with Azure App Configuration
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
using Azure.Identity; | |
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | |
namespace MusicStore.Web | |
{ | |
public class Program | |
{ | |
... | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => { | |
webBuilder.UseStartup<Startup>(); | |
}) | |
.ConfigureAppConfiguration((context, config) => { | |
var settings = config.Build(); | |
var appConfigEndpoint = settings["AppSettings:AppConfiguration:Endpoint"]; | |
var userAssignedIdentityClientId = settings["AppSettings:Identity:ClientId"]; | |
if (!string.IsNullOrEmpty(appConfigEndpoint)) | |
{ | |
var endpoint = new Uri(appConfigEndpoint); | |
config.AddAzureAppConfiguration(options => | |
{ | |
options | |
// Use managed identity to access app configuration | |
.Connect(endpoint, new ManagedIdentityCredential(clientId: userAssignedIdentityClientId)) | |
// Use managed identity to configure Key Vault | |
.ConfigureKeyVault(vaultOpt => | |
{ | |
vaultOpt.SetCredential(new ManagedIdentityCredential(clientId: userAssignedIdentityClientId)); | |
}); | |
... | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment