Skip to content

Commit

Permalink
Cherry pick branch 'genexuslabs:http-client-authentication' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiamurialdo authored and Beta Bot committed Jan 6, 2025
1 parent 5195249 commit c49fc99
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,19 @@ public string get_ProxyHost()
{
return _proxyHost;
}
#if NETCORE
private static Encoding ISO_8859_1 = Encoding.Latin1;
#else
private static Encoding ISO_8859_1 = Encoding.GetEncoding("ISO-8859-1");
#endif
private const string AuthenticationSchemeBasic = "Basic";
public void AddAuthentication(int scheme, string realm, string user, string password)
{
if (scheme >= _Basic && scheme <= _Kerberos)
_authCollection.Add(new GxAuthScheme(scheme, realm, user, password));
if (scheme == _Basic) {
string authHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{user}:{password}"));
AddHeader(HttpHeader.AUTHORIZATION, new AuthenticationHeaderValue("Basic", authHeader).ToString());
string authHeader = Convert.ToBase64String(ISO_8859_1.GetBytes($"{user}:{password}"));
AddHeader(HttpHeader.AUTHORIZATION, new AuthenticationHeaderValue(AuthenticationSchemeBasic, authHeader).ToString());
}
}

Expand Down Expand Up @@ -1038,7 +1044,7 @@ async Task ReadResponseDataAsync()
}
}
}
#endif
#endif
bool UseOldHttpClient(string name)
{
if (Config.GetValueOf("useoldhttpclient", out string useOld) && useOld.StartsWith("y", StringComparison.OrdinalIgnoreCase))
Expand Down

0 comments on commit c49fc99

Please sign in to comment.