Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Created January 29, 2020 16:14
Show Gist options
  • Save kasunkv/22094dd5162dccb1014215e939c68dfc to your computer and use it in GitHub Desktop.
Save kasunkv/22094dd5162dccb1014215e939c68dfc to your computer and use it in GitHub Desktop.
Use user-assigned managed identity to access Azure App Configuration
using Azure.Identity;
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
// Provide the client id of the User-Assigned Managed identity
.Connect(endpoint, new ManagedIdentityCredential(clientId: userAssignedIdentityClientId))
.UseFeatureFlags();
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment