diff --git a/API_README.md b/API_README.md index 43506aa2f..0d0f8f236 100644 --- a/API_README.md +++ b/API_README.md @@ -5,7 +5,7 @@ Allows customers to easily access the Okta Management APIs This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: 5.1.0 -- SDK version: 8.0.0 +- SDK version: 8.0.1 - Build package: org.openapitools.codegen.languages.CSharpNetCoreClientCodegen For more information, please visit [https://developer.okta.com/](https://developer.okta.com/) diff --git a/README.md b/README.md index 2f19eeb82..e93935ee2 100644 --- a/README.md +++ b/README.md @@ -433,7 +433,7 @@ This library looks for configuration in the following sources: Higher numbers win. In other words, configuration passed via the constructor will override configuration found in environment variables, which will override configuration in `okta.yaml` (if any), and so on. Note that `json` files cannot be used if they contain JavaScript comments. Comments are not allowed by JSON format. - + ### YAML configuration When you use an API Token instead of OAuth 2.0 the full YAML configuration looks like: @@ -510,6 +510,15 @@ okta: rateLimit: maxRetries: 4 ``` + + Beginning in version 8.0.1, If you have need for a `proxy` node in your configuration unrelated to a web proxy for the Okta API client or you want to disable the proxy without removing it from your configuration, set `useProxy` to `false`: + + ```json + { + "useProxy" : false + "proxy" : "non web proxy settings" + } + ``` ### Environment variables diff --git a/openapi3/config.json b/openapi3/config.json index 2e8b675c4..1f2182b01 100644 --- a/openapi3/config.json +++ b/openapi3/config.json @@ -6,7 +6,7 @@ "packageName" : "Okta.Sdk", "outputDir" : "../", "inputSpec" : "./management.yaml", - "packageVersion" : "8.0.0", + "packageVersion" : "8.0.1", "packageDescription" : "Official .NET SDK for the Okta API", "packageTitle" : "Official .NET SDK for the Okta API", "packageCompany" : "Okta, Inc.", diff --git a/openapi3/templates/ApiClient.mustache b/openapi3/templates/ApiClient.mustache index 70716a88d..4e54fbd94 100644 --- a/openapi3/templates/ApiClient.mustache +++ b/openapi3/templates/ApiClient.mustache @@ -486,7 +486,7 @@ namespace {{packageName}}.Client { clientOptions.Proxy = _proxy; } - else if (configuration.Proxy != null) + else if (configuration.Proxy != null && configuration.UseProxy == true) { clientOptions.Proxy = ProxyConfiguration.GetProxy(configuration.Proxy); } diff --git a/openapi3/templates/Configuration.mustache b/openapi3/templates/Configuration.mustache index 7252160f7..97ac9d249 100644 --- a/openapi3/templates/Configuration.mustache +++ b/openapi3/templates/Configuration.mustache @@ -395,6 +395,7 @@ namespace {{packageName}}.Client [System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] public Configuration() { + UseProxy = true; // Set to true to avoid change of default behavior. See #691. Proxy = null; UserAgent = "{{httpUserAgent}}{{^httpUserAgent}}/{{{gitRepoId}}}/csharp/oasv3{{/httpUserAgent}}"; OktaDomain = "{{{basePath}}}"; @@ -587,6 +588,13 @@ namespace {{packageName}}.Client /// X509 Certificate collection. public X509CertificateCollection ClientCertificates { get; set; } + /// + /// Gets or sets a value indicating whether to use the proxy settings defined + /// in the Proxy node of the configuration. + /// + /// Value indicating whether to use the proxy settings defined in the Proxy node. + public bool? UseProxy { get; set; } + /// /// Gets or sets the access token for OAuth2 authentication. /// diff --git a/openapi3/templates/IReadableConfiguration.mustache b/openapi3/templates/IReadableConfiguration.mustache index 103563d82..7cfe06649 100644 --- a/openapi3/templates/IReadableConfiguration.mustache +++ b/openapi3/templates/IReadableConfiguration.mustache @@ -12,6 +12,13 @@ namespace {{packageName}}.Client /// public interface IReadableConfiguration { + /// + /// Gets or sets a value indicating whether to use the proxy settings defined + /// in the Proxy node of the configuration. + /// + /// Value indicating whether to use the proxy settings defined in the Proxy node. + bool? UseProxy { get; set; } + /// /// Gets the access token. /// diff --git a/src/Okta.Sdk.UnitTest/Api/ApiClientShould.cs b/src/Okta.Sdk.UnitTest/Api/ApiClientShould.cs index 7a9fc79b2..8febb89a2 100644 --- a/src/Okta.Sdk.UnitTest/Api/ApiClientShould.cs +++ b/src/Okta.Sdk.UnitTest/Api/ApiClientShould.cs @@ -11,6 +11,8 @@ using Polly; using RestSharp; using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; using RichardSzalay.MockHttp; namespace Okta.Sdk.UnitTest.Api @@ -381,5 +383,40 @@ public async Task AddHeadersWhenRetrying401DpopTokenRequest() dpopHeader = request.Parameters.FirstOrDefault(x => x.Name == "DPoP"); dpopHeader.Value.Should().Be("myDpopJwt2"); } + + // Test for the conditions described in the github issue comment here: https://github.com/okta/okta-sdk-dotnet/issues/691#issuecomment-2130299272 + [Fact] + public void NotFailOnEmptyProxyConfig() + { + Exception thrown = null; + string appSettingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); + try + { + dynamic appsettings = new + { + useProxy = false, // advice to the configuration system not to treat proxy section as http client proxy. + // Assume that it is used in an unrelated way + // see https://github.com/okta/okta-sdk-dotnet/issues/691#issuecomment-2130299272 + proxy = new + { + host = "not a good uri" + } + }; + + File.WriteAllText(appSettingsPath, JsonConvert.SerializeObject(appsettings)); + var apiClient = new ApiClient(); + var client = apiClient.GetConfiguredClient(Configuration.GetConfigurationOrDefault()); + } + catch (Exception ex) + { + thrown = ex; + } + finally + { + File.Delete(appSettingsPath); + } + + thrown.Should().BeNull("because no exception was thrown"); + } } } diff --git a/src/Okta.Sdk.UnitTest/Okta.Sdk.UnitTest.csproj b/src/Okta.Sdk.UnitTest/Okta.Sdk.UnitTest.csproj index 194a2b71a..6823680cc 100644 --- a/src/Okta.Sdk.UnitTest/Okta.Sdk.UnitTest.csproj +++ b/src/Okta.Sdk.UnitTest/Okta.Sdk.UnitTest.csproj @@ -3,7 +3,7 @@ Okta.Sdk.UnitTest Okta.Sdk.UnitTest - net7.0 + net8.0 false diff --git a/src/Okta.Sdk/Client/ApiClient.cs b/src/Okta.Sdk/Client/ApiClient.cs index e997539e4..860264d33 100644 --- a/src/Okta.Sdk/Client/ApiClient.cs +++ b/src/Okta.Sdk/Client/ApiClient.cs @@ -476,7 +476,7 @@ internal RestClient GetConfiguredClient(IReadableConfiguration configuration) { clientOptions.Proxy = _proxy; } - else if (configuration.Proxy != null) + else if (configuration.Proxy != null && configuration.UseProxy == true) { clientOptions.Proxy = ProxyConfiguration.GetProxy(configuration.Proxy); } diff --git a/src/Okta.Sdk/Client/Configuration.cs b/src/Okta.Sdk/Client/Configuration.cs index deef5d838..684c28df1 100644 --- a/src/Okta.Sdk/Client/Configuration.cs +++ b/src/Okta.Sdk/Client/Configuration.cs @@ -39,7 +39,7 @@ public class Configuration : IReadableConfiguration /// Version of the package. /// /// Version of the package. - public const string Version = "8.0.0"; + public const string Version = "8.0.1"; /// /// Identifier for ISO 8601 DateTime Format @@ -386,6 +386,7 @@ public static void Validate(IReadableConfiguration configuration) [System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] public Configuration() { + UseProxy = true; // Set to true to avoid change of default behavior. See #691. Proxy = null; UserAgent = "/okta-sdk-dotnet/csharp/oasv3"; OktaDomain = "https://subdomain.okta.com"; @@ -555,6 +556,13 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier) /// X509 Certificate collection. public X509CertificateCollection ClientCertificates { get; set; } + /// + /// Gets or sets a value indicating whether to use the proxy settings defined + /// in the Proxy node of the configuration. + /// + /// Value indicating whether to use the proxy settings defined in the Proxy node. + public bool? UseProxy { get; set; } + /// /// Gets or sets the access token for OAuth2 authentication. /// @@ -758,7 +766,7 @@ public static string ToDebugReport() report += " OS: " + System.Environment.OSVersion + "\n"; report += " .NET Framework Version: " + System.Environment.Version + "\n"; report += " Version of the API: 5.1.0\n"; - report += " SDK Package Version: 8.0.0\n"; + report += " SDK Package Version: 8.0.1\n"; return report; } diff --git a/src/Okta.Sdk/Client/IReadableConfiguration.cs b/src/Okta.Sdk/Client/IReadableConfiguration.cs index 418a9f482..124126c02 100644 --- a/src/Okta.Sdk/Client/IReadableConfiguration.cs +++ b/src/Okta.Sdk/Client/IReadableConfiguration.cs @@ -21,6 +21,13 @@ namespace Okta.Sdk.Client /// public interface IReadableConfiguration { + /// + /// Gets or sets a value indicating whether to use the proxy settings defined + /// in the Proxy node of the configuration. + /// + /// Value indicating whether to use the proxy settings defined in the Proxy node. + bool? UseProxy { get; set; } + /// /// Gets the access token. /// diff --git a/src/Okta.Sdk/Okta.Sdk.csproj b/src/Okta.Sdk/Okta.Sdk.csproj index 74032fddf..8991e1fb9 100644 --- a/src/Okta.Sdk/Okta.Sdk.csproj +++ b/src/Okta.Sdk/Okta.Sdk.csproj @@ -13,7 +13,7 @@ Official .NET SDK for the Okta API Okta, Inc. Okta.Sdk - 8.0.0 + 8.0.1 bin\$(Configuration)\$(TargetFramework)\Okta.Sdk.xml LICENSE True