feross / simple-get

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines
MIT License
401 stars 50 forks source link

basic auth support #57

Closed alessioalex closed 3 years ago

alessioalex commented 4 years ago

Hey @feross would you be open to a pull request to support basic auth? I know there's already OAuth but basic auth is still used here and there.

Flet commented 4 years ago

I wonder if this could be documented in the README like the oauth technique is (without adding code).

Maybe something like:

const user = 'someuser'
const pass = 'pa$$word'
const encodedAuth = Buffer.from(`${user}:${pass}`).toString('base64')

get('http://example.com', {
  headers: {
    'user-agent': `my-module/${pkg.version} (https://github.com/username/my-module)`,
    authorization: `Basic ${encodedAuth}`
  }
})
alessioalex commented 4 years ago

Did not see that at the time I posted this. Considering that's the approach for OAuth, the http auth should be like the one in @Flet 's example (included in the README).

feross commented 3 years ago

Thanks for the code snippet, @Flet. Just added it to the readme!