Environment Specific AppSettings not honored.
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
Hi @rcollette,
Thanks for reporting this. Our team will review it and prioritize it accordingly.
Internal Ref: OKTA-637428
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.
@rcollette, we have received a PR to handle this issue. We would love to get your feedback on the proposed changes https://github.com/okta/okta-sdk-dotnet/pull/653
I have a posted a dirty workaround until that PR finally is merged:
https://github.com/okta/okta-sdk-dotnet/issues/646#issuecomment-2025487664