0

I have AzureADB2C object in my ASP.NET MVC application stored in the appsettings.json file.

I want to store Azure AzureADB2C object as a Key Vault secret and then access it from Program.cs like so:

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureADB2C"));

How can I do it?

I implemented cloud authentication in my app using the following instruction

2 Answers 2

0

You'd use the Azure Key Vault configuration provider which allows you to store configuration values as Key Vault secrets and access them through the IConfiguration and IOptions interfaces, the same as configuration values stored in appsettings.json.

While you can store the entire B2C configuration in Key Vault I'd say that it's not really necessary. Typically I'd only configure the client secret in Key Vault, everything else I'd put in my normal config store (app service environment variables, Azure Configuration Manager, etc).

Sign up to request clarification or add additional context in comments.

Comments

0

Based on this answer I was able to do the following changes

In Program.cs before adding authentication with Microsoft identity platform, I pasted the following code:

IConfiguration azureADB2C = builder.Configuration.GetSection("AzureADB2C");

azureADB2C["TenantId"] = builder.Configuration.GetSection("TenantId").Value;
azureADB2C["ClientId"] = builder.Configuration.GetSection("ClientId").Value;
azureADB2C["ClientSecret"] = builder.Configuration.GetSection("ClientSecret").Value;

In appsettings.json I left the corresponding values empty:

"AzureAdB2C": {
  "TenantId": "",
  "ClientId": "",
  "ClientSecret": "",
  ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.