Skip to content

SocketsHttpHandler NTLM doesn't work #25391

@Tratcher

Description

@Tratcher

Version 2.1.0-preview2-26308-01

Negotiate works, NTLM doesn't. It doesn't even make a second request, it returns the first 401.

Repro:

        public static void Main(string[] args)
        {
            var serverTask = RunServer();
            Console.WriteLine("Press any key to send request.");
            Console.ReadKey();
            var clientTask = RunClient();
            Task.WaitAll(serverTask, clientTask);
        }

        private static async Task RunServer()
        {
            var listener = new HttpListener();
            listener.Prefixes.Add("http://localhost:8080/");
            listener.AuthenticationSchemes = System.Net.AuthenticationSchemes.Ntlm;
            listener.Start();
            var context = await listener.GetContextAsync();
            context.Response.Close();
        }

        private static async Task RunClient()
        {
            Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER", "true");
            var handler = new HttpClientHandler();
            handler.UseDefaultCredentials = true;
            var client = new HttpClient(handler);
            var response  = await client.GetAsync("http://localhost:8080/");
            Console.WriteLine(response);
        }

Expected result: 200 OK

Press any key to send request.
 StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
{
  Date: Fri, 09 Mar 2018 23:49:25 GMT
  Transfer-Encoding: chunked
  Server: Microsoft-HTTPAPI/2.0
}

Actual: 401 Unauthorized

Press any key to send request.
 StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{
  Server: Microsoft-HTTPAPI/2.0
  WWW-Authenticate: NTLM [Token]
  Date: Fri, 09 Mar 2018 23:48:29 GMT
  Content-Length: 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockingMarks issues that we want to fast track in order to unblock other important workbug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions