使用安全密钥流从命令行登录

🌐 Sign in from the command line using security-key flow

  1. 在命令行中,输入 npm login 命令。

  2. 出现提示时,提供你的用户名、密码和电子邮件地址。

    user@host:~$ npm login
    npm notice Log in on https://registry.npmjs.org/
    Username: mona
    Password:
    Email: (this IS public) mona@github.com
    npm notice Open https://www.npmjs.com/login/913c3ab1-89a0-44bd-be8d-d946e2e906f0 to use your security key for authentication or enter OTP from your authenticator app
  3. 如果你已经配置了安全密钥,请打开命令行中显示的提供的 URL。或者,如果你已经配置了移动身份验证器,请跳到第 6 步。

  4. 点击使用安全密钥,然后按照浏览器的具体步骤进行身份验证。

    Screenshot showing security key prompt
  5. 复制生成的令牌

    Screenshot showing a sample token generated while using WebAuthn for cli login
  6. 在 CLI 提示符中输入一次性密码。

    输入一次性密码:

使用 --auth-type=web 从命令行登录

🌐 Sign in from the command line using --auth-type=web

npm 8.14.0 及更高版本支持通过浏览器进行登录流程。在 npm 9 中,这将成为 npm 公共注册表的默认行为。

🌐 npm 8.14.0 and higher support login flow through the browsers. This will become the default behavior for the npm public registry in npm 9.

使用现有的浏览器会话

🌐 With an existing browser session

  1. 在命令行中,输入 npm login --auth-type=web 命令。

  2. 当出现提示时,按“回车”键以打开浏览器开始登录流程,或点击命令行中提供的 URL。

    user@host:~$ npm login
    npm notice Log in on https://registry.npmjs.org/
    Authenticate your account at:
    https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922
    Press ENTER to open in the browser...
  3. 点击使用安全密钥,然后按照浏览器的具体步骤进行身份验证。

    Screenshot showing security key prompt

    注意:如果你已配置使用 TOTP,你将会看到 TOTP 提示

没有现有的浏览器会话

🌐 Without an existing browser session

  1. 在命令行中,输入 npm login --auth-type=web 命令。

  2. 当出现提示时,按“回车”键以打开浏览器开始登录流程,或点击命令行中提供的 URL。

    user@host:~$ npm login
    npm notice Log in on https://registry.npmjs.org/
    Authenticate your account at:
    https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922
    Press ENTER to open in the browser...
  3. 在 npm“登录”页面上,输入您的帐户详细信息并单击登录 Screenshot of npm login dialog
  4. 点击使用安全密钥,然后按照浏览器的具体步骤进行身份验证。

    Screenshot showing security key prompt

    注意:如果你已配置使用 TOTP,你将会看到 TOTP 提示