Created
January 29, 2020 16:14
-
-
Save kasunkv/22094dd5162dccb1014215e939c68dfc to your computer and use it in GitHub Desktop.
Use user-assigned managed identity to access 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; | |
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