Exemplo n.º 1
0
 return Bluebird.try(() => {
   // if they're using legacy auth currently then we have to update them to a
   // bearer token before continuing.
   if (conf.auth.basic) {
     log.info('profile', 'Updating authentication to bearer token')
     return profile.login(conf.auth.basic.username, conf.auth.basic.password, conf).then((result) => {
       if (!result.token) throw new Error('Your registry ' + conf.registry + 'does not seem to support bearer tokens. Bearer tokens are required for two-factor authentication')
       npm.config.setCredentialsByURI(conf.registry, {token: result.token})
       return Bluebird.fromNode((cb) => npm.config.save('user', cb))
     })
   }
 }).then(() => {
Exemplo n.º 2
0
 }).then((e) => {
   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) => {
Exemplo n.º 3
0
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)
      })
    }).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.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
    })
}
Exemplo n.º 4
0
 return read.otp('Authenticator provided OTP:').then((otp) => {
   auth.otp = otp
   return profile.login(username, password, {registry: registry, auth: auth})
 })