From 2a96c31d8a0bcec500c18ffed411fe5985d19082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Mon, 23 May 2022 16:13:30 +0200 Subject: [PATCH 1/4] feat: Add --use-webauth flag --- lib/commands/adduser.js | 1 + lib/utils/config/definitions.js | 10 ++++++++++ tap-snapshots/test/lib/commands/config.js.test.cjs | 2 ++ tap-snapshots/test/lib/load-all-commands.js.test.cjs | 4 ++-- tap-snapshots/test/lib/npm.js.test.cjs | 4 ++-- .../test/lib/utils/config/definitions.js.test.cjs | 11 +++++++++++ .../test/lib/utils/config/describe-all.js.test.cjs | 11 +++++++++++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/commands/adduser.js b/lib/commands/adduser.js index 755abea8eb9eb..3488c8689320b 100644 --- a/lib/commands/adduser.js +++ b/lib/commands/adduser.js @@ -14,6 +14,7 @@ class AddUser extends BaseCommand { static params = [ 'registry', 'scope', + 'use-webauth', ] static ignoreImplicitWorkspace = true diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index 92fbbd1e6dc20..6dbe1500437cb 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -2158,6 +2158,16 @@ define('usage', { `, }) +define('use-webauth', { + default: false, + type: Boolean, + description: ` + When set to true, npm authenticates with a web browser. When + false, it uses username and password via the terminal. +`, + flatten, +}) + define('user-agent', { default: 'npm/{npm-version} ' + 'node/{node-version} ' + diff --git a/tap-snapshots/test/lib/commands/config.js.test.cjs b/tap-snapshots/test/lib/commands/config.js.test.cjs index fe392344ed35a..3bddb21859104 100644 --- a/tap-snapshots/test/lib/commands/config.js.test.cjs +++ b/tap-snapshots/test/lib/commands/config.js.test.cjs @@ -151,6 +151,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna "unicode": false, "update-notifier": true, "usage": false, + "use-webauth": false, "user-agent": "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}", "version": false, "versions": false, @@ -307,6 +308,7 @@ umask = 0 unicode = false update-notifier = true usage = false +use-webauth = false user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}" ; userconfig = "{HOME}/.npmrc" ; overridden by cli version = false diff --git a/tap-snapshots/test/lib/load-all-commands.js.test.cjs b/tap-snapshots/test/lib/load-all-commands.js.test.cjs index b8c274b085a7a..95acd51fc4dbb 100644 --- a/tap-snapshots/test/lib/load-all-commands.js.test.cjs +++ b/tap-snapshots/test/lib/load-all-commands.js.test.cjs @@ -32,7 +32,7 @@ Usage: npm adduser Options: -[--registry ] [--scope <@scope>] +[--registry ] [--scope <@scope>] [--use-webauth] aliases: login, add-user @@ -522,7 +522,7 @@ Usage: npm adduser Options: -[--registry ] [--scope <@scope>] +[--registry ] [--scope <@scope>] [--use-webauth] aliases: login, add-user diff --git a/tap-snapshots/test/lib/npm.js.test.cjs b/tap-snapshots/test/lib/npm.js.test.cjs index e71bc8268c495..b9cb216717483 100644 --- a/tap-snapshots/test/lib/npm.js.test.cjs +++ b/tap-snapshots/test/lib/npm.js.test.cjs @@ -189,7 +189,7 @@ All commands: npm adduser Options: - [--registry ] [--scope <@scope>] + [--registry ] [--scope <@scope>] [--use-webauth] aliases: login, add-user @@ -600,7 +600,7 @@ All commands: npm adduser Options: - [--registry ] [--scope <@scope>] + [--registry ] [--scope <@scope>] [--use-webauth] aliases: login, add-user diff --git a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs index b12dccdb76c31..367b36127d645 100644 --- a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs @@ -146,6 +146,7 @@ Array [ "unicode", "update-notifier", "usage", + "use-webauth", "user-agent", "userconfig", "version", @@ -1845,6 +1846,16 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for usage Show short usage output about the command specified. ` +exports[`test/lib/utils/config/definitions.js TAP > config description for use-webauth 1`] = ` +#### \`use-webauth\` + +* Default: false +* Type: Boolean + +When set to true, npm authenticates with a web browser. When false, it uses +username and password via the terminal. +` + exports[`test/lib/utils/config/definitions.js TAP > config description for user-agent 1`] = ` #### \`user-agent\` diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index cacbe96a74f35..a7fd2c95d48c1 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -1599,6 +1599,17 @@ Show short usage output about the command specified. +#### \`use-webauth\` + +* Default: false +* Type: Boolean + +When set to true, npm authenticates with a web browser. When false, it uses +username and password via the terminal. + + + + #### \`user-agent\` * Default: "npm/{npm-version} node/{node-version} {platform} {arch} From ab703b0631640622325b87a259f53c9de6b40a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Mon, 23 May 2022 16:29:32 +0200 Subject: [PATCH 2/4] Add docs --- docs/content/commands/npm-adduser.md | 11 +++++++++++ docs/content/using-npm/config.md | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/content/commands/npm-adduser.md b/docs/content/commands/npm-adduser.md index 06eeb379c4dd8..35354120077ae 100644 --- a/docs/content/commands/npm-adduser.md +++ b/docs/content/commands/npm-adduser.md @@ -87,6 +87,17 @@ npm init --scope=@foo --yes ``` + + + +#### `use-webauth` + +* Default: false +* Type: Boolean + +When set to true, npm authenticates with a web browser. When false, it uses +username and password via the terminal. + diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md index 12b508582af1c..9498ef8b5893c 100644 --- a/docs/content/using-npm/config.md +++ b/docs/content/using-npm/config.md @@ -1726,6 +1726,17 @@ Show short usage output about the command specified. +#### `use-webauth` + +* Default: false +* Type: Boolean + +When set to true, npm authenticates with a web browser. When false, it uses +username and password via the terminal. + + + + #### `user-agent` * Default: "npm/{npm-version} node/{node-version} {platform} {arch} From 82af4e4be9b529e825d3eba1f2262894dc585fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Wed, 25 May 2022 10:15:33 +0200 Subject: [PATCH 3/4] Switch from a separate flag to a variation of auth-type --- docs/content/commands/npm-adduser.md | 13 ++++++++----- docs/content/using-npm/config.md | 19 +++++-------------- lib/commands/adduser.js | 3 ++- lib/utils/config/definitions.js | 16 ++++------------ .../test/lib/commands/config.js.test.cjs | 2 -- .../test/lib/load-all-commands.js.test.cjs | 6 ++++-- tap-snapshots/test/lib/npm.js.test.cjs | 6 ++++-- .../lib/utils/config/definitions.js.test.cjs | 19 +++++-------------- .../lib/utils/config/describe-all.js.test.cjs | 15 +++------------ 9 files changed, 35 insertions(+), 64 deletions(-) diff --git a/docs/content/commands/npm-adduser.md b/docs/content/commands/npm-adduser.md index 35354120077ae..9f7caeb9cdc90 100644 --- a/docs/content/commands/npm-adduser.md +++ b/docs/content/commands/npm-adduser.md @@ -90,13 +90,16 @@ npm init --scope=@foo --yes -#### `use-webauth` +#### `auth-type` -* Default: false -* Type: Boolean +* Default: "legacy" +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" +* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in + a future version of npm in favor of web-based login. -When set to true, npm authenticates with a web browser. When false, it uses -username and password via the terminal. +What authentication strategy to use with `adduser`/`login`. + +Pass `webauthn` to use a web-based login. diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md index 9498ef8b5893c..4e9e67d970ba2 100644 --- a/docs/content/using-npm/config.md +++ b/docs/content/using-npm/config.md @@ -1726,17 +1726,6 @@ Show short usage output about the command specified. -#### `use-webauth` - -* Default: false -* Type: Boolean - -When set to true, npm authenticates with a web browser. When false, it uses -username and password via the terminal. - - - - #### `user-agent` * Default: "npm/{npm-version} node/{node-version} {platform} {arch} @@ -1902,12 +1891,14 @@ When set to `dev` or `development`, this is an alias for `--include=dev`. #### `auth-type` * Default: "legacy" -* Type: "legacy", "sso", "saml", or "oauth" -* DEPRECATED: This method of SSO/SAML/OAuth is deprecated and will be removed - in a future version of npm in favor of web-based login. +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" +* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in + a future version of npm in favor of web-based login. What authentication strategy to use with `adduser`/`login`. +Pass `webauthn` to use a web-based login. + diff --git a/lib/commands/adduser.js b/lib/commands/adduser.js index 3488c8689320b..cf467b7a73a5e 100644 --- a/lib/commands/adduser.js +++ b/lib/commands/adduser.js @@ -3,6 +3,7 @@ const replaceInfo = require('../utils/replace-info.js') const BaseCommand = require('../base-command.js') const authTypes = { legacy: require('../auth/legacy.js'), + webauthn: require('../auth/legacy.js'), oauth: require('../auth/oauth.js'), saml: require('../auth/saml.js'), sso: require('../auth/sso.js'), @@ -14,7 +15,7 @@ class AddUser extends BaseCommand { static params = [ 'registry', 'scope', - 'use-webauth', + 'auth-type', ] static ignoreImplicitWorkspace = true diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index 6dbe1500437cb..4032c552e24bb 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -238,13 +238,15 @@ define('audit-level', { define('auth-type', { default: 'legacy', - type: ['legacy', 'sso', 'saml', 'oauth'], + type: ['legacy', 'webauthn', 'sso', 'saml', 'oauth'], deprecated: ` - This method of SSO/SAML/OAuth is deprecated and will be removed in + The SSO/SAML/OAuth methods are deprecated and will be removed in a future version of npm in favor of web-based login. `, description: ` What authentication strategy to use with \`adduser\`/\`login\`. + + Pass \`webauthn\` to use a web-based login. `, flatten, }) @@ -2158,16 +2160,6 @@ define('usage', { `, }) -define('use-webauth', { - default: false, - type: Boolean, - description: ` - When set to true, npm authenticates with a web browser. When - false, it uses username and password via the terminal. -`, - flatten, -}) - define('user-agent', { default: 'npm/{npm-version} ' + 'node/{node-version} ' + diff --git a/tap-snapshots/test/lib/commands/config.js.test.cjs b/tap-snapshots/test/lib/commands/config.js.test.cjs index 3bddb21859104..fe392344ed35a 100644 --- a/tap-snapshots/test/lib/commands/config.js.test.cjs +++ b/tap-snapshots/test/lib/commands/config.js.test.cjs @@ -151,7 +151,6 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna "unicode": false, "update-notifier": true, "usage": false, - "use-webauth": false, "user-agent": "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}", "version": false, "versions": false, @@ -308,7 +307,6 @@ umask = 0 unicode = false update-notifier = true usage = false -use-webauth = false user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}" ; userconfig = "{HOME}/.npmrc" ; overridden by cli version = false diff --git a/tap-snapshots/test/lib/load-all-commands.js.test.cjs b/tap-snapshots/test/lib/load-all-commands.js.test.cjs index 95acd51fc4dbb..876f5eaabdec0 100644 --- a/tap-snapshots/test/lib/load-all-commands.js.test.cjs +++ b/tap-snapshots/test/lib/load-all-commands.js.test.cjs @@ -32,7 +32,8 @@ Usage: npm adduser Options: -[--registry ] [--scope <@scope>] [--use-webauth] +[--registry ] [--scope <@scope>] +[--auth-type ] aliases: login, add-user @@ -522,7 +523,8 @@ Usage: npm adduser Options: -[--registry ] [--scope <@scope>] [--use-webauth] +[--registry ] [--scope <@scope>] +[--auth-type ] aliases: login, add-user diff --git a/tap-snapshots/test/lib/npm.js.test.cjs b/tap-snapshots/test/lib/npm.js.test.cjs index b9cb216717483..11ca08140b289 100644 --- a/tap-snapshots/test/lib/npm.js.test.cjs +++ b/tap-snapshots/test/lib/npm.js.test.cjs @@ -189,7 +189,8 @@ All commands: npm adduser Options: - [--registry ] [--scope <@scope>] [--use-webauth] + [--registry ] [--scope <@scope>] + [--auth-type ] aliases: login, add-user @@ -600,7 +601,8 @@ All commands: npm adduser Options: - [--registry ] [--scope <@scope>] [--use-webauth] + [--registry ] [--scope <@scope>] + [--auth-type ] aliases: login, add-user diff --git a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs index 367b36127d645..d67f3e6fe0bd7 100644 --- a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs @@ -146,7 +146,6 @@ Array [ "unicode", "update-notifier", "usage", - "use-webauth", "user-agent", "userconfig", "version", @@ -254,11 +253,13 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for auth- #### \`auth-type\` * Default: "legacy" -* Type: "legacy", "sso", "saml", or "oauth" -* DEPRECATED: This method of SSO/SAML/OAuth is deprecated and will be removed - in a future version of npm in favor of web-based login. +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" +* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in + a future version of npm in favor of web-based login. What authentication strategy to use with \`adduser\`/\`login\`. + +Pass \`webauthn\` to use a web-based login. ` exports[`test/lib/utils/config/definitions.js TAP > config description for before 1`] = ` @@ -1846,16 +1847,6 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for usage Show short usage output about the command specified. ` -exports[`test/lib/utils/config/definitions.js TAP > config description for use-webauth 1`] = ` -#### \`use-webauth\` - -* Default: false -* Type: Boolean - -When set to true, npm authenticates with a web browser. When false, it uses -username and password via the terminal. -` - exports[`test/lib/utils/config/definitions.js TAP > config description for user-agent 1`] = ` #### \`user-agent\` diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index a7fd2c95d48c1..270c397ec2cd8 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -1599,17 +1599,6 @@ Show short usage output about the command specified. -#### \`use-webauth\` - -* Default: false -* Type: Boolean - -When set to true, npm authenticates with a web browser. When false, it uses -username and password via the terminal. - - - - #### \`user-agent\` * Default: "npm/{npm-version} node/{node-version} {platform} {arch} @@ -1775,12 +1764,14 @@ When set to \`dev\` or \`development\`, this is an alias for \`--include=dev\`. #### \`auth-type\` * Default: "legacy" -* Type: "legacy", "sso", "saml", or "oauth" +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" * DEPRECATED: This method of SSO/SAML/OAuth is deprecated and will be removed in a future version of npm in favor of web-based login. What authentication strategy to use with \`adduser\`/\`login\`. +Pass \`webauthn\` to use a web-based login. + From 13831bf882dd74da99e43c27b78e5ba6610b035c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Wed, 25 May 2022 10:20:23 +0200 Subject: [PATCH 4/4] Update snapshot --- tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index 270c397ec2cd8..853e758dcd600 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -1765,8 +1765,8 @@ When set to \`dev\` or \`development\`, this is an alias for \`--include=dev\`. * Default: "legacy" * Type: "legacy", "webauthn", "sso", "saml", or "oauth" -* DEPRECATED: This method of SSO/SAML/OAuth is deprecated and will be removed - in a future version of npm in favor of web-based login. +* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in + a future version of npm in favor of web-based login. What authentication strategy to use with \`adduser\`/\`login\`.