diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-04-05 22:51:49 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-04-05 23:00:02 +0200 |
commit | e37effe4cec98688e75d770f4d0b7f68927e2b73 (patch) | |
tree | e7efa0fc8a2139f9aba4b66ea3f3613262f20cef /deps/npm/lib/auth | |
parent | 026f6b787a7a23597790f1f0b076c58a68c7c38b (diff) | |
download | node-new-e37effe4cec98688e75d770f4d0b7f68927e2b73.tar.gz |
Revert "deps: upgrade npm to 5.8.0"
This reverts commit 25a816dcda7b1db0929501acfe13f2fe5119759b.
PR-URL: https://github.com/nodejs/node/pull/19837
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'deps/npm/lib/auth')
-rw-r--r-- | deps/npm/lib/auth/legacy.js | 92 |
1 files changed, 35 insertions, 57 deletions
diff --git a/deps/npm/lib/auth/legacy.js b/deps/npm/lib/auth/legacy.js index 08de61bff0..92bf44c119 100644 --- a/deps/npm/lib/auth/legacy.js +++ b/deps/npm/lib/auth/legacy.js @@ -6,74 +6,52 @@ const npm = require('../npm.js') const output = require('../utils/output.js') const pacoteOpts = require('../config/pacote') const fetchOpts = require('../config/fetch-opts') -const opener = require('opener') -const openerPromise = (url) => new Promise((resolve, reject) => { - opener(url, { command: npm.config.get('browser') }, (er) => er ? reject(er) : resolve()) -}) +module.exports.login = function login (creds, registry, scope, cb) { + let username = creds.username || '' + let password = creds.password || '' + let email = creds.email || '' + const auth = {} + if (npm.config.get('otp')) auth.otp = npm.config.get('otp') -const loginPrompter = (creds) => { - const opts = { log: log } - return read.username('Username:', creds.username, opts).then((u) => { - creds.username = u - return read.password('Password:', creds.password) + return read.username('Username:', username, {log: log}).then((u) => { + username = u + return read.password('Password: ', password) }).then((p) => { - creds.password = p - return read.email('Email: (this IS public) ', creds.email, opts) + password = p + return read.email('Email: (this IS public) ', email, {log: log}) }).then((e) => { - creds.email = e - return creds - }) -} - -module.exports.login = (creds, registry, scope, cb) => { - const conf = { - log: log, - creds: creds, - registry: registry, - auth: { - otp: npm.config.get('otp') - }, - scope: scope, - opts: fetchOpts.fromPacote(pacoteOpts()) - } - login(conf).then((newCreds) => cb(null, newCreds)).catch(cb) -} - -function login (conf) { - return profile.login(openerPromise, loginPrompter, conf) - .catch((err) => { - if (err.code === 'EOTP') throw err - const u = conf.creds.username - const p = conf.creds.password - const e = conf.creds.email - if (!(u && p && e)) throw err - return profile.adduserCouch(u, e, p, conf) - }) - .catch((err) => { - if (err.code !== 'EOTP') throw err - return read.otp('Authenticator provided OTP:').then((otp) => { - conf.auth.otp = otp - const u = conf.creds.username - const p = conf.creds.password - return profile.loginCouch(u, p, conf) + email = e + return profile.login(username, password, {registry: registry, auth: auth}).catch((err) => { + if (err.code === 'EOTP') throw err + return profile.adduser(username, email, password, { + registry: registry, + opts: fetchOpts.fromPacote(pacoteOpts()) + }) + }).catch((err) => { + if (err.code === 'EOTP' && !auth.otp) { + return read.otp('Authenticator provided OTP:').then((otp) => { + auth.otp = otp + return profile.login(username, password, {registry: registry, auth: auth}) + }) + } else { + throw err + } }) }).then((result) => { const newCreds = {} if (result && result.token) { newCreds.token = result.token } else { - newCreds.username = conf.creds.username - newCreds.password = conf.creds.password - newCreds.email = conf.creds.email + newCreds.username = username + newCreds.password = password + newCreds.email = email newCreds.alwaysAuth = npm.config.get('always-auth') } - const usermsg = conf.creds.username ? ' user ' + conf.creds.username : '' - conf.log.info('login', 'Authorized' + usermsg) - const scopeMessage = conf.scope ? ' to scope ' + conf.scope : '' - const userout = conf.creds.username ? ' as ' + conf.creds.username : '' - output('Logged in%s%s on %s.', userout, scopeMessage, conf.registry) - return newCreds - }) + log.info('adduser', 'Authorized user %s', username) + const scopeMessage = scope ? ' to scope ' + scope : '' + output('Logged in as %s%s on %s.', username, scopeMessage, registry) + cb(null, newCreds) + }).catch(cb) } |