Reputation:
I am using npm REQUEST for a simple http call. There is ambiguity (at least for me) as to what the hash requirement means. From the documentation I see I need to make a chained function call:
request.get('http://some.server.com/').auth('username', 'password', false);
The fine print says "...If passed as an option, auth should be a hash containing values username, password..."
Could someone kindly explain the hashing process? Is it something like this?
cypto.createHash('md5').update('fake_username').digest('hex')
Here is the full code sample I am working on in nodejs. I get a 401 error
var request = require('request')
var cypto = require('crypto')
var unhash = cypto.createHash('md5').update('fake_username').digest('hex')
var pwhash = cypto.createHash('md5').update('fake_password').digest('hex')
request.get('<URL HERE>', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
else {
console.log('Response code: ', response.statusCode)
}
}).auth(unhash,pwhash,false)
Upvotes: 1
Views: 1108
Reputation: 106698
The If passed as an option, auth should be a hash containing values username, password
part is referring to the second example in the readme:
request.get('http://some.server.com/', {
'auth': {
'user': 'username',
'pass': 'password',
'sendImmediately': false
}
});
Here 'hash' means 'object'. It has nothing to do with cryptographic hashing.
Upvotes: 2