node/deps/npm/node_modules/npm-registry-client/lib/authify.js
Forrest L Norvell e79ccee168 npm: upgrade to v2.1.18
PR-URL: https://github.com/iojs/io.js/pull/266
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-08 23:49:03 +01:00

24 lines
677 B
JavaScript

module.exports = authify
function authify (authed, parsed, headers, credentials) {
if (credentials && credentials.token) {
this.log.verbose("request", "using bearer token for auth")
headers.authorization = "Bearer " + credentials.token
return null
}
if (authed) {
if (credentials && credentials.username && credentials.password) {
var username = encodeURIComponent(credentials.username)
var password = encodeURIComponent(credentials.password)
parsed.auth = username + ":" + password
}
else {
return new Error(
"This request requires auth credentials. Run `npm login` and repeat the request."
)
}
}
}