Skip to content

Commit

Permalink
OKTA-723081: fix invalid uri exception (#722)
Browse files Browse the repository at this point in the history
* OKTA-723081: add proxy related configuration to address #691

---------

Co-authored-by: Laura Rodríguez <[email protected]>
  • Loading branch information
bryanapellanes-okta and laura-rodriguez authored Jun 26, 2024
1 parent 101a6a8 commit 45c8589
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion API_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion openapi3/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion openapi3/templates/ApiClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions openapi3/templates/Configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}";
Expand Down Expand Up @@ -587,6 +588,13 @@ namespace {{packageName}}.Client
/// <value>X509 Certificate collection.</value>
public X509CertificateCollection ClientCertificates { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to use the proxy settings defined
/// in the Proxy node of the configuration.
/// </summary>
/// <value>Value indicating whether to use the proxy settings defined in the Proxy node.</value>
public bool? UseProxy { get; set; }

/// <summary>
/// Gets or sets the access token for OAuth2 authentication.
///
Expand Down
7 changes: 7 additions & 0 deletions openapi3/templates/IReadableConfiguration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace {{packageName}}.Client
/// </summary>
public interface IReadableConfiguration
{
/// <summary>
/// Gets or sets a value indicating whether to use the proxy settings defined
/// in the Proxy node of the configuration.
/// </summary>
/// <value>Value indicating whether to use the proxy settings defined in the Proxy node.</value>
bool? UseProxy { get; set; }

/// <summary>
/// Gets the access token.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions src/Okta.Sdk.UnitTest/Api/ApiClientShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}
}
2 changes: 1 addition & 1 deletion src/Okta.Sdk.UnitTest/Okta.Sdk.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Okta.Sdk.UnitTest</AssemblyName>
<RootNamespace>Okta.Sdk.UnitTest</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Okta.Sdk/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Okta.Sdk/Client/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Configuration : IReadableConfiguration
/// Version of the package.
/// </summary>
/// <value>Version of the package.</value>
public const string Version = "8.0.0";
public const string Version = "8.0.1";

/// <summary>
/// Identifier for ISO 8601 DateTime Format
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -555,6 +556,13 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier)
/// <value>X509 Certificate collection.</value>
public X509CertificateCollection ClientCertificates { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to use the proxy settings defined
/// in the Proxy node of the configuration.
/// </summary>
/// <value>Value indicating whether to use the proxy settings defined in the Proxy node.</value>
public bool? UseProxy { get; set; }

/// <summary>
/// Gets or sets the access token for OAuth2 authentication.
///
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Okta.Sdk/Client/IReadableConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace Okta.Sdk.Client
/// </summary>
public interface IReadableConfiguration
{
/// <summary>
/// Gets or sets a value indicating whether to use the proxy settings defined
/// in the Proxy node of the configuration.
/// </summary>
/// <value>Value indicating whether to use the proxy settings defined in the Proxy node.</value>
bool? UseProxy { get; set; }

/// <summary>
/// Gets the access token.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Okta.Sdk/Okta.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Description>Official .NET SDK for the Okta API</Description>
<Copyright>Okta, Inc.</Copyright>
<RootNamespace>Okta.Sdk</RootNamespace>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Okta.Sdk.xml</DocumentationFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
Expand Down

0 comments on commit 45c8589

Please sign in to comment.