-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathhttpntlm.js
44 lines (36 loc) · 1.1 KB
/
httpntlm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var async = require('async');
var httpreq = require('httpreq');
var ntlm = require('./ntlm');
var HttpsAgent = require('agentkeepalive').HttpsAgent;
var keepaliveAgent = new HttpsAgent();
exports.get = function(options, callback){
if(!options.workstation) options.workstation = '';
if(!options.domain) options.domain = '';
async.waterfall([
function ($){
var type1msg = ntlm.createType1Message(options);
httpreq.get(options.url, {
headers:{
'Connection' : 'keep-alive',
'Authorization': type1msg
},
agent: keepaliveAgent
}, $);
},
function (res, $){
if(!res.headers['www-authenticate'])
return $(new Error('www-authenticate not found on response of second request'));
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);
var type3msg = ntlm.createType3Message(type2msg, options);
httpreq.get(options.url, {
headers:{
'Connection' : 'Close',
'Authorization': type3msg
},
allowRedirects: false,
agent: keepaliveAgent
}, $);
}
], callback);
}
exports.ntlm = ntlm; //if you want to use the NTML functions yourself