joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

Basic AUTH support #22

Closed pkoretic closed 8 years ago

pkoretic commented 8 years ago

it would be nice to have basic auth support same as request module

auth: { 'user': 'username', 'pass': 'password' }

manually creating them as part of uri or header doesn't really scale well

joepie91 commented 8 years ago

This can already be done using for example the basic-auth-header module:

var bhttp = require("bhttp");
var basicAuthHeader = require("basic-auth-header");

bhttp.get("http://example.com/", {
    headers: {
        Authorization: basicAuthHeader("username", "password")
    }
});

Since basic authentication is just a header like any other, there's not really any value in adding it to bhttp itself - it would increase complexity quite a bit for no real end-user gain, as it's already trivial to add a header anyway. It would also invite requests for many other authentication schemes being added, which makes the complexity issue worse.

I'm not sure I see your point that it "doesn't scale well" - what relation is there between authentication headers and scalability?

pkoretic commented 8 years ago

I'm using it like that, just without basicAuthHeader function, it seems more complicated than just providing auth object but I get your point scaling was just a reference that manually inserting http://username:auth@uri or adding autorization header is minor PITA, you need some wrappers, so out of the box is not that friendly if you have more than one url to write

joepie91 commented 8 years ago

Sure, but that's unrelated to scalability. I understand that it's a bit more work, but:

pkoretic commented 8 years ago

@joepie91 That sounds great, maybe writing this (http basic auth example) in README would be good idea for future reference