Skip to content

Commit

Permalink
Close npm#804 Pass auth for tarball fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 13, 2011
1 parent 307031e commit 33ce37a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/utils/fetch.js
Expand Up @@ -15,6 +15,7 @@ var http
, mkdir = require("./mkdir-p")
, consts = require("constants")
, proxyify = require("./proxyify")
, regUrl = npm.cofig.get("registry")

module.exports = fetch
function fetch (remote, local, headers, cb) {
Expand Down Expand Up @@ -46,9 +47,21 @@ function fetch_ (remote, local, headers, cb) {
function fetchAndWrite (remote, fstr, headers, maxRedirects, redirects) {
if (!redirects) redirects = 0
if (!maxRedirects) maxRedirects = 10

headers = headers || {}
var remote = url.parse(remote)
, opts =
{ headers: headers || {}
if (remote.host === regUrl && npm.config.get("always-auth")) {
var auth = npm.config.get("_auth")
if (!auth) return fstr.emit("error", new Error(
"Auth required and none provided. Please run 'npm adduser'"))
headers.authentication = "Basic "+auth
} else if (remote.auth) {
headers.authentication = "Basic "
+ (new Buffer(remote.auth).toString("base64"))
}

var opts =
{ headers: headers
, path: (remote.pathname||"/")+(remote.search||"")+(remote.hash||"")
, host: remote.hostname
, port: remote.port
Expand Down

0 comments on commit 33ce37a

Please sign in to comment.