Skip to content

Add support for environment variables for configuration #2480

@markjritchie

Description

@markjritchie

As far as I can see there is no way to use environment variables to override the appsettings.json for the downstream API.

The file src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquirerFactory.cs has the following method:

private IConfiguration ReadConfiguration()
        {
            if (Configuration == null)
            {
                // Read the configuration from a file
                var builder = new ConfigurationBuilder();
                string basePath = DefineConfiguration(builder);
                builder.SetBasePath(basePath)
                       .AddJsonFile("appsettings.json", optional: true);
                Configuration = builder.Build();
            }
            return Configuration;
        }

Changing it to:

private IConfiguration ReadConfiguration()
        {
            if (Configuration == null)
            {
                // Read the configuration from a file
                var builder = new ConfigurationBuilder();
                string basePath = DefineConfiguration(builder);
                builder.SetBasePath(basePath)
                       .AddJsonFile("appsettings.json", optional: true)
                       .AddEnvironmentVariables();
                Configuration = builder.Build();
            }
            return Configuration;
        }

would provide better flexibility.

Alternatively a way to pass in the configuration to be used would also work.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions