I'm using the urllib npm package with the following code:
options = {
method: 'GET',
rejectUnauthorized: false,
digestAuth: `${user}:${pass}`
}
urllib.request(uri, options, function (err, data, res) {
if (err) {
throw err; // you need to handle error
}
console.log(res.statusCode);
console.log(res.headers);
// data is Buffer instance
console.log(data.toString());
})
Unfortunately, I'm getting a 401 error back:
401 { 'content-length': '222', 'content-type': 'text/plain',
connection: 'close', 'www-authenticate': 'Digest realm="000f7c16eacc", nonce="8652e7dfa50f6124896b84142eef93b5", stale="false", algorithm="MD5", qop="auth"', 'x-frame-options': 'SAMEORIGIN' } { "Response": { "ResponseURL": "/images/snapshot.jpg", "ResponseCode": 3, "SubResponseCode": 0, "ResponseString": "Not Authorized", "StatusCode": 401, "StatusString": "Unauthorized", "Data": "null" } }
The same uri, username, and password works when accessing via postman. What configuration details am I missing in this request? urllib doesn't provide a digest auth example.
I am not married to urllib and will take any working nodejs solution for pulling an image from an digest-auth endpoint.