trouble-in-terror-town/node_modules/another-npm-registry-client/lib/authify.js
Mikolaj 2bbacbea09 did some more work on networking and removed EOS in favor of LRM
did some more work on networking and removed EOS in favor of Light Reflective Mirror
2022-05-31 15:04:31 +02:00

26 lines
815 B
JavaScript

module.exports = authify
function authify (authed, parsed, headers, credentials) {
if (credentials && credentials.otp) {
this.log.verbose('request', 'passing along npm otp')
headers['npm-otp'] = credentials.otp
}
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.'
)
}
}
}