-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Milestone
Description
Description
I'm using an on-premise exchange server with NTLM v2 authentication.
When attempting to authenticate using HttpClient and AndroidMessageHandler, I encounter a 401 Unauthorized error, specifically due to a self-signed certificate. Interestingly, when using a public certificate, authentication proceeds without any issues.
Old ticket: #102107
Issue still reproducible using .NET9
Here parts of the code:
var _httpClientHandler = new CustomAndroidMessageHandler();
var _credentials = new CredentialCache
{
{ new Uri(serverEndpoint), "NTLM", new NetworkCredential(emailEntry.Text, passwordEntry.Text)}
};
_httpClientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
_httpClientHandler.Credentials = _credentials;
HttpClient httpclient = new HttpClient(_httpClientHandler);public class CustomAndroidMessageHandler : AndroidMessageHandler
{
protected override async Task WriteRequestContentToOutput(
HttpRequestMessage request,
HttpURLConnection httpConnection,
CancellationToken cancellationToken)
{
var stream = await request.Content.ReadAsStreamAsync().ConfigureAwait(false);
await stream.CopyToAsync(httpConnection.OutputStream!, 4096, cancellationToken).ConfigureAwait(false);
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}
}
}I added
<AndroidUseNegotiateAuthentication>true</AndroidUseNegotiateAuthentication>in csproj
Reproduction Steps
.
Expected behavior
Working.
Actual behavior
401 Unauthorized.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Reactions are currently unavailable