Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Specific AppSettings not honored. #656

Open
rcollette opened this issue Aug 9, 2023 · 4 comments
Open

Environment Specific AppSettings not honored. #656

rcollette opened this issue Aug 9, 2023 · 4 comments
Labels

Comments

@rcollette
Copy link

Describe the bug?

Environment specific configurations are not honored.

What is expected to happen?

Configuration that is present in appsetting.development.json (and others) should override the settings in appsettings.json

What is the actual behavior?

The SDK is only looking at configuration properties in appsettings.json

Reproduction Steps?

Create an SDK configuration in appsettings.json that has an invalid token

    "okta": {
        "client": {
            "connectionTimeout": 30000,
            "oktaDomain": "https://my.oktapreview.com",
            "token": "xxxxxInvalidToken",
            "requestTimeout": 0,
            "rateLimit": {
                "maxRetries": 4
            }
        }
    },

Create a valid configuration in appsettings.development.json

    "okta": {
        "client": {
            "connectionTimeout": 30000,
            "oktaDomain": "https://syncsort.oktapreview.com",
            "token": "a valid token",
            "requestTimeout": 0,
            "rateLimit": {
                "maxRetries": 4
            }
        }
    },

Use a launchSetttings.json file like:

{
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:45774",
            "sslPort": 44329
        }
    },
    "profiles": {
        "My.Api.Web": {
            "commandName": "Project",
            "launchBrowser": true,
            "launchUrl": "swagger",
            "applicationUrl": "https://localhost:5001;http://localhost:5000",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        }
    }
}

Set the following environment variable
ASPNETCORE_ENVIRONMENT=Development

OKTA api calls will fail with this configuration, when running in local (development) mode.

Additional Information?

No response

.NET Version

7.0.306

SDK Version

6.0.11

OS version

Darwin MacBook-Pro-3.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

@rcollette rcollette added the bug label Aug 9, 2023
@laura-rodriguez
Copy link
Collaborator

Hi @rcollette,

Thanks for reporting this. Our team will review it and prioritize it accordingly.

Internal Ref: OKTA-637428

@rcollette
Copy link
Author

The root of this issue is that this library is not using the standard .NET configuration apis, and it's really creating a conundrum for me.

https://learn.microsoft.com/en-us/dotnet/core/extensions/configuration

I should be able to do

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddSingleton<IConfiguration>(
                _ => new ConfigurationBuilder()
                    .AddJsonFile("appsettings.json", true)
                    .AddEnvironmentVariables()
                    .Build())
            .AddSingleton<IUserApi, UserApi>()            
            # My own class that uses IUserApi
            .AddSingleton<IOktaUserClient, OktaUserClient>()
}

and it should just work.

@laura-rodriguez
Copy link
Collaborator

laura-rodriguez commented Oct 3, 2023

@rcollette, we have received a PR to handle this issue. We would love to get your feedback on the proposed changes
#653

@mmoreno79
Copy link

I have a posted a dirty workaround until that PR finally is merged:

#646 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants