Skip to content

Commit e4a1f17

Browse files
zkataeschright
authored andcommitted
token: fix otp for create and remove (#175)
PR-URL: #175 Fixes: https://npm.community/t/npm-token-create-doesnt-work-in-6-6-0-6-9-0/6259 Credit: @zkat Reviewed-By: @aeschright
1 parent d075471 commit e4a1f17

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

Diff for: lib/token.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const npm = require('./npm.js')
55
const figgyPudding = require('figgy-pudding')
66
const npmConfig = require('./config/figgy-config.js')
77
const output = require('./utils/output.js')
8+
const otplease = require('./utils/otplease.js')
89
const Table = require('cli-table3')
910
const Bluebird = require('bluebird')
1011
const isCidrV4 = require('is-cidr').v4
@@ -80,6 +81,7 @@ function generateTokenIds (tokens, minLength) {
8081
}
8182

8283
const TokenConfig = figgyPudding({
84+
auth: {},
8385
registry: {},
8486
otp: {},
8587
cidr: {},
@@ -185,13 +187,8 @@ function rm (args) {
185187
}
186188
})
187189
return Bluebird.map(toRemove, (key) => {
188-
return profile.removeToken(key, conf).catch((ex) => {
189-
if (ex.code !== 'EOTP') throw ex
190-
log.info('token', 'failed because revoking this token requires OTP')
191-
return readUserInfo.otp().then((otp) => {
192-
conf.auth.otp = otp
193-
return profile.removeToken(key, conf)
194-
})
190+
return otplease(conf, conf => {
191+
return profile.removeToken(key, conf)
195192
})
196193
})
197194
})).then(() => {
@@ -213,15 +210,9 @@ function create (args) {
213210
const validCIDR = validateCIDRList(cidr)
214211
return readUserInfo.password().then((password) => {
215212
log.info('token', 'creating')
216-
return profile.createToken(password, readonly, validCIDR, conf).catch((ex) => {
217-
if (ex.code !== 'EOTP') throw ex
218-
log.info('token', 'failed because it requires OTP')
219-
return readUserInfo.otp().then((otp) => {
220-
conf.auth.otp = otp
221-
log.info('token', 'creating with OTP')
222-
return pulseTillDone.withPromise(profile.createToken(password, readonly, validCIDR, conf))
223-
})
224-
})
213+
return pulseTillDone.withPromise(otplease(conf, conf => {
214+
return profile.createToken(password, readonly, validCIDR, conf)
215+
}))
225216
}).then((result) => {
226217
delete result.key
227218
delete result.updated

0 commit comments

Comments
 (0)