I ran into a problem with retrieving configuration from Azure App Configuration in Startup methods.
public static IConfigurationSection GetAuthSection()
{
var intermediateConfig = new ConfigurationBuilder().AddJsonFile("appsettings.json", true).Build();
var appConfiguration = intermediateConfig["AppConfigurationConnectionString"];
var builder = new ConfigurationBuilder();
if (!string.IsNullOrWhiteSpace(appConfiguration))
{
builder.AddAzureAppConfiguration(opt =>
{
opt.Connect(appConfiguration).Select("Tool*");
});
}
var configRoot = builder.Build();
var debugConfig = configRoot.GetDebugView();
return configRoot.GetSection("Tool:Auth");
}
GetDebugView
method returns such string that is OK for me.
Tool:
Auth:
CallbackPath=***
ClientId=***
ClientSecret=***
Instance=***
Scopes=***
SignedOutCallbackPath=***
TenantId=***
But method GetSection
returns null in Value
property.
Method GetAuthSection
is used in Startup.cs in method ConfigureServices
:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(ConfigurationLoader.GetAuthSection());
...
}
I can't hold Auth data in the local config due to some reasons. After the server is built and it is running these data can be retrieved from the configuration.