Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace {{packageName}}.Client
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -67,6 +70,14 @@ namespace {{packageName}}.Client
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -133,8 +144,7 @@ namespace {{packageName}}.Client
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : {{#net90OrLater}}HttpUtility.UrlEncode({{/net90OrLater}}parameter.Key{{#net90OrLater}}){{/net90OrLater}};
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HttpSigningConfiguration()
{
HashAlgorithm = HashAlgorithmName.SHA256;
SigningAlgorithm = "PKCS1-v15";
string framework = RuntimeInformation.FrameworkDescription;
_skipUrlEncode = framework.StartsWith(".NET ") &&
int.TryParse(framework.Substring(5).Split('.')[0], out int fwMajor) && fwMajor >= 9;
}

/// <summary>
Expand Down Expand Up @@ -75,6 +78,14 @@ public HttpSigningConfiguration()
/// </summary>
public int SignatureValidityPeriod { get; set; }

// On .NET 9+, HttpUtility.ParseQueryString already URL-encodes keys internally,
// so calling UrlEncode again would cause double-encoding and produce a signature
// that does not match the actual request sent by RestSharp 112+.
// On .NET 8 and earlier, keys must be explicitly URL-encoded so that special
// characters (e.g. '$' in OData params like $filter) are encoded the same way
// in the signature as they are in the outgoing HTTP request.
private readonly bool _skipUrlEncode;

private enum PrivateKeyType
{
None = 0,
Expand Down Expand Up @@ -141,8 +152,7 @@ public Dictionary<string, string> GetHttpSignedHeader(string basePath,string met
foreach (var parameter in requestOptions.QueryParameters)
{
#if (NETCOREAPP)
string framework = RuntimeInformation.FrameworkDescription;
string key = framework.StartsWith(".NET 9") ? parameter.Key : parameter.Key;
string key = _skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
if (parameter.Value.Count > 1)
{ // array
foreach (var value in parameter.Value)
Expand Down
Loading
Loading