node-phantom icon indicating copy to clipboard operation
node-phantom copied to clipboard

Possible to add http basic auth headers or settings?

Open starsinmypockets opened this issue 11 years ago • 3 comments

Is it possible to add http basic auth headers to request?

starsinmypockets avatar Feb 12 '14 19:02 starsinmypockets

+1

michaelklem avatar Feb 16 '14 09:02 michaelklem

This worked for me: See http://www.webtoolkit.info/javascript-base64.html#.UwCSKEJdVcg for Base64 code.

ph.createPage(function(err,page) { var authentication_data = {"Authorization": "Basic " + Base64.encode("my_domain:my_password")}; page.set('customHeaders', authentication_data, function(err){ // do something now }); });

btoa was not working for me so I resorted to the Base64 example.

michaelklem avatar Feb 16 '14 11:02 michaelklem

Used a slightly different approach but this works:

return ph.createPage(function(err,page) { var authentication_data = {"Authorization": "Basic " + new Buffer("name:pass").toString('base64')}; page.set('customHeaders', authentication_data, function(err){ //... access htauth page here }); });

starsinmypockets avatar Feb 20 '14 21:02 starsinmypockets