Skip to content

Add support for environment variables for configuration #2480

Closed

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.

Activity

  1. jmprieur commented on Sep 27, 2023

    @jmprieur
    Collaborator

    Thanks markjritchie
    Would you like to propose a PR?

  2. markjritchie commented on Sep 27, 2023

    @markjritchie
    ContributorAuthor

    Happy to, but thought I should check that I wasn't missing something

  3. markjritchie commented on Sep 27, 2023

    @markjritchie
    ContributorAuthor

    Is there a guide on setting up the necessary PAT to push to a branch and create the PR?

    I get authentication failed when I try to push the branch

  4. jmprieur commented on Sep 27, 2023

    @jmprieur
    Collaborator

    No. there is no PAT. You would have to fork the repo.

  5. added this to the 2.14.1 milestone on Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions