Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default auth-type to legacy if otp is configured #6044

Merged
merged 1 commit into from Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -238,6 +238,7 @@ define('auth-type', {
type: ['legacy', 'web'],
description: `
What authentication strategy to use with \`login\`.
Note that if an \`otp\` config is given, this value will always be set to \`legacy\`.
`,
flatten,
})
Expand Down Expand Up @@ -1465,7 +1466,13 @@ define('otp', {
If not set, and a registry response fails with a challenge for a one-time
password, npm will prompt on the command line for one.
`,
flatten,
flatten (key, obj, flatOptions) {
flatten(key, obj, flatOptions)
if (obj.otp) {
obj['auth-type'] = 'legacy'
flatten('auth-type', obj, flatOptions)
}
},
})

define('package', {
Expand Down
3 changes: 2 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Expand Up @@ -654,7 +654,8 @@ exit code.
* Default: "web"
* Type: "legacy" or "web"

What authentication strategy to use with \`login\`.
What authentication strategy to use with \`login\`. Note that if an \`otp\`
config is given, this value will always be set to \`legacy\`.

#### \`before\`

Expand Down
9 changes: 9 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -931,3 +931,12 @@ t.test('remap global-style', t => {
t.strictSame(flat, { installStrategy: 'shallow' })
t.end()
})

t.test('otp changes auth-type', t => {
const obj = { 'auth-type': 'web', otp: 123456 }
const flat = {}
mockDefs().otp.flatten('otp', obj, flat)
t.strictSame(flat, { authType: 'legacy', otp: 123456 })
t.strictSame(obj, { 'auth-type': 'legacy', otp: 123456 })
t.end()
})