4

I'm trying to make a request using Node behind a corporate web proxy which requires NTLM authentication. I've tried using a couple libraries such as the proxying-agent but am having little success.

Here's a simplified version of my code using the request library and ntlm.js similar to the proxying-agent. I'd expect to receive a successful response after the last request call but for some reason am still getting a 407 -

var ntlmRequest = function(req) {
    var ntlmOptions = {};
    ntlmOptions.ntlm = {};
    ntlmOptions.method = 'GET';
    ntlmOptions.path = 'http://www.jsonip.co.uk';
    ntlmOptions.ntlm.username = 'USERNAME';
    ntlmOptions.ntlm.password = 'Pa$$word';
    ntlmOptions.ntlm.workstation = 'PC-NAME';
    ntlmOptions.ntlm.domain = 'DOMAIN';

var type1message = ntlm.createType1Message(ntlmOptions.ntlm);

var requestOptions = {
    url: 'http://www.jsonip.co.uk',
    proxy: 'http://webproxy.domain.com:8080',
    headers: req.headers
};

requestOptions.headers['Proxy-Authorization'] = type1message;
requestOptions.headers['Proxy-Connection'] = 'Keep-Alive'

request(requestOptions, function(err,res){

    var type2message = ntlm.parseType2Message(res.headers['proxy-authenticate']);

    var type3message = ntlm.createType3Message(type2message, ntlmOptions.ntlm);

    requestOptions.headers['Proxy-Authorization'] = type3message;

    request(requestOptions, function(err,res){
        console.log(res.statusCode);
    });
}); 
};

I've tried comparing some packet captures and on a working NTLM request (using curl) I can see this during the type 1 and type 3 requests -

[HTTP request 1/2]
[HTTP request 2/2]

My requests only show 1/1.

I'm thinking maybe in other implementations of NTLM the browsers are spanning the requests across multiple packets. Not sure if this is the reason why it isn't working, or maybe just a different way of doing things.

Thanks in advance.

Chris Edgington
  • 2,937
  • 5
  • 23
  • 42

0 Answers0