+129
-76
lines changedFilter options
+129
-76
lines changed Original file line number Diff line number Diff line change
@@ -116,11 +116,15 @@ class Access extends BaseCommand {
116
116
}
117
117
118
118
async #grant (permissions, scope, pkg) {
119
-
await libnpmaccess.setPermissions(scope, pkg, permissions, this.npm.flatOptions)
119
+
await otplease(this.npm, this.npm.flatOptions, async (opts) => {
120
+
await libnpmaccess.setPermissions(scope, pkg, permissions, opts)
121
+
})
120
122
}
121
123
122
124
async #revoke (scope, pkg) {
123
-
await libnpmaccess.removePermissions(scope, pkg, this.npm.flatOptions)
125
+
await otplease(this.npm, this.npm.flatOptions, async (opts) => {
126
+
await libnpmaccess.removePermissions(scope, pkg, opts)
127
+
})
124
128
}
125
129
126
130
async #listPackages (owner, pkg) {
Original file line number Diff line number Diff line change
@@ -222,6 +222,8 @@ class Profile extends BaseCommand {
222
222
}
223
223
224
224
async enable2fa (args) {
225
+
const conf = { ...this.npm.flatOptions }
226
+
225
227
if (args.length > 1) {
226
228
throw new Error('npm profile enable-2fa [auth-and-writes|auth-only]')
227
229
}
@@ -244,9 +246,16 @@ class Profile extends BaseCommand {
244
246
)
245
247
}
246
248
249
+
const userInfo = await get(conf)
250
+
251
+
if (!userInfo?.tfa?.pending && userInfo?.tfa?.mode === mode) {
252
+
output.standard('Two factor authentication is already enabled and set to ' + mode)
253
+
return
254
+
}
255
+
247
256
const info = {
248
257
tfa: {
249
-
mode: mode,
258
+
mode,
250
259
},
251
260
}
252
261
@@ -296,25 +305,15 @@ class Profile extends BaseCommand {
296
305
const password = await readUserInfo.password()
297
306
info.tfa.password = password
298
307
299
-
log.info('profile', 'Determine if tfa is pending')
300
-
const userInfo = await get({ ...this.npm.flatOptions })
301
-
302
-
const conf = { ...this.npm.flatOptions }
303
308
if (userInfo && userInfo.tfa && userInfo.tfa.pending) {
304
309
log.info('profile', 'Resetting two-factor authentication')
305
310
await set({ tfa: { password, mode: 'disable' } }, conf)
306
-
} else if (userInfo && userInfo.tfa) {
307
-
if (!conf.otp) {
308
-
conf.otp = await readUserInfo.otp(
309
-
'Enter one-time password: '
310
-
)
311
-
}
312
311
}
313
312
314
313
log.info('profile', 'Setting two-factor authentication to ' + mode)
315
-
const challenge = await set(info, conf)
314
+
const challenge = await otplease(this.npm, conf, o => set(info, o))
316
315
317
-
if (challenge.tfa === null) {
316
+
if (challenge.tfa && challenge.tfa.mode) {
318
317
output.standard('Two factor authentication mode changed to: ' + mode)
319
318
return
320
319
}
@@ -358,8 +357,8 @@ class Profile extends BaseCommand {
358
357
}
359
358
360
359
async disable2fa () {
361
-
const conf = { ...this.npm.flatOptions }
362
-
const info = await get(conf)
360
+
const opts = { ...this.npm.flatOptions }
361
+
const info = await get(opts)
363
362
364
363
if (!info.tfa || info.tfa.pending) {
365
364
output.standard('Two factor authentication not enabled.')
@@ -368,14 +367,8 @@ class Profile extends BaseCommand {
368
367
369
368
const password = await readUserInfo.password()
370
369
371
-
if (!conf.otp) {
372
-
const msg = 'Enter one-time password: '
373
-
conf.otp = await readUserInfo.otp(msg)
374
-
}
375
-
376
370
log.info('profile', 'disabling tfa')
377
-
378
-
await set({ tfa: { password: password, mode: 'disable' } }, conf)
371
+
await otplease(this.npm, opts, o => set({ tfa: { password: password, mode: 'disable' } }, o))
379
372
380
373
if (this.npm.config.get('json')) {
381
374
output.buffer({ tfa: false })
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4