Skip to content

Commit

Permalink
Add Managed Identity credentials for authenticating with App Configur…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
DrizzlyOwl committed Sep 5, 2024
1 parent f90c429 commit c543f90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions DfE.FindInformationAcademiesTrusts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,23 @@ private static void AddEnvironmentVariablesTo(WebApplicationBuilder builder)
builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly());

// Retrieve the connection string
string? connectionString = builder.Configuration.GetConnectionString("AppConfig");
string? appConfigConnectionString = builder.Configuration.GetConnectionString("AppConfig");

// Load App Configuration and Feature Flags from Azure
builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(connectionString).UseFeatureFlags(),
true
);
if (!string.IsNullOrEmpty(appConfigConnectionString))
{
// Check to see if a Managed Identity has been set
string? azureClientId = builder.Configuration.GetSection("AZURE_CLIENT_ID").Value;

// Register App Configuration
builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(
new Uri(appConfigConnectionString),
new ManagedIdentityCredential(azureClientId)
).UseFeatureFlags(),
true
);
}

builder.Services.AddOptions<TestOverrideOptions>()
.Bind(builder.Configuration.GetSection(TestOverrideOptions.ConfigurationSection));
Expand Down

0 comments on commit c543f90

Please sign in to comment.