Skip to content

Commit cf175fb

Browse files
authored
fix: default auth-type to legacy if otp is configured (#6044)
1 parent ca8ff00 commit cf175fb

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/utils/config/definitions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ define('auth-type', {
238238
type: ['legacy', 'web'],
239239
description: `
240240
What authentication strategy to use with \`login\`.
241+
Note that if an \`otp\` config is given, this value will always be set to \`legacy\`.
241242
`,
242243
flatten,
243244
})
@@ -1465,7 +1466,13 @@ define('otp', {
14651466
If not set, and a registry response fails with a challenge for a one-time
14661467
password, npm will prompt on the command line for one.
14671468
`,
1468-
flatten,
1469+
flatten (key, obj, flatOptions) {
1470+
flatten(key, obj, flatOptions)
1471+
if (obj.otp) {
1472+
obj['auth-type'] = 'legacy'
1473+
flatten('auth-type', obj, flatOptions)
1474+
}
1475+
},
14691476
})
14701477

14711478
define('package', {

tap-snapshots/test/lib/docs.js.test.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ exit code.
654654
* Default: "web"
655655
* Type: "legacy" or "web"
656656
657-
What authentication strategy to use with \`login\`.
657+
What authentication strategy to use with \`login\`. Note that if an \`otp\`
658+
config is given, this value will always be set to \`legacy\`.
658659
659660
#### \`before\`
660661

test/lib/utils/config/definitions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,12 @@ t.test('remap global-style', t => {
931931
t.strictSame(flat, { installStrategy: 'shallow' })
932932
t.end()
933933
})
934+
935+
t.test('otp changes auth-type', t => {
936+
const obj = { 'auth-type': 'web', otp: 123456 }
937+
const flat = {}
938+
mockDefs().otp.flatten('otp', obj, flat)
939+
t.strictSame(flat, { authType: 'legacy', otp: 123456 })
940+
t.strictSame(obj, { 'auth-type': 'legacy', otp: 123456 })
941+
t.end()
942+
})

0 commit comments

Comments
 (0)