kartykp/upgrade-path-to-regex
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: Accessing npm using two-factor authentication |
| 3 | redirect_from: |
| 4 | - /getting-started/using-two-factor-authentication |
| 5 | --- |
| 6 | |
| 7 | import shared from '~/shared.js' |
| 8 | |
| 9 | ## Sign in from the command line using security-key flow |
| 10 | |
| 11 | 1. On the command line, type the [`npm login`][login] command. |
| 12 | |
| 13 | 2. When prompted, provide your username, password, and email address. |
| 14 | |
| 15 | ``` |
| 16 | user@host:~$ npm login |
| 17 | npm notice Log in on https://registry.npmjs.org/ |
| 18 | Username: mona |
| 19 | Password: |
| 20 | Email: (this IS public) mona@github.com |
| 21 | 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 |
| 22 | ``` |
| 23 | |
| 24 | 3. If you have configured a security-key, open the provided URL shown in the command line. Alternatively, if you have configured a mobile authenticator skip to step 6. |
| 25 | |
| 26 | 4. Click on _Use security key_ and follow the browser specific steps to authenticate. |
| 27 | |
| 28 | <Screenshot src="/getting-started/setting-up-your-npm-user-account/2fa-use-security-key.png" alt="Screenshot showing security key prompt" /> |
| 29 | |
| 30 | 5. Copy the generated token |
| 31 | |
| 32 | <Screenshot src="/getting-started/setting-up-your-npm-user-account/webauthn-cli-login-token.png" alt="Screenshot showing a sample token generated while using WebAuthn for cli login" /> |
| 33 | |
| 34 | 6. Enter the one-time password into the CLI prompt. |
| 35 | |
| 36 | <Prompt>Enter one-time password:</Prompt> |
| 37 | |
| 38 | ## Sign in from the command line using `--auth-type=web` |
| 39 | |
| 40 | 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. |
| 41 | |
| 42 | ### With an existing browser session |
| 43 | |
| 44 | 1. On the command line, type the [`npm login --auth-type=web`][login] command. |
| 45 | |
| 46 | 2. When prompted hit "ENTER" to open your browser to start the login flow or click the provided URL show in the command line. |
| 47 | |
| 48 | ``` |
| 49 | user@host:~$ npm login |
| 50 | npm notice Log in on https://registry.npmjs.org/ |
| 51 | Authenticate your account at: |
| 52 | https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922 |
| 53 | Press ENTER to open in the browser... |
| 54 | ``` |
| 55 | |
| 56 | 3. Click on _Use security key_ and follow the browser specific steps to authenticate. |
| 57 | |
| 58 | <Screenshot src="/getting-started/setting-up-your-npm-user-account/2fa-use-security-key.png" alt="Screenshot showing security key prompt" /> |
| 59 | |
| 60 | _Note: If you have configured to use TOTP, you will see an TOTP prompt instead_ |
| 61 | |
| 62 | ### Without an existing browser session |
| 63 | |
| 64 | 1. On the command line, type the [`npm login --auth-type=web`][login] command. |
| 65 | |
| 66 | 2. When prompted hit "ENTER" to open your browser to start the login flow or click the provided URL show in the command line. |
| 67 | |
| 68 | ``` |
| 69 | user@host:~$ npm login |
| 70 | npm notice Log in on https://registry.npmjs.org/ |
| 71 | Authenticate your account at: |
| 72 | https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922 |
| 73 | Press ENTER to open in the browser... |
| 74 | ``` |
| 75 | |
| 76 | 3. <>{shared['user-login'].text}</> |
| 77 | |
| 78 | <>{shared['user-login'].image}</> |
| 79 | |
| 80 | 4. Click on _Use security key_ and follow the browser specific steps to authenticate. |
| 81 | |
| 82 | <Screenshot src="/getting-started/setting-up-your-npm-user-account/2fa-use-security-key.png" alt="Screenshot showing security key prompt" /> |
| 83 | |
| 84 | _Note: If you have configured to use TOTP, you will see an TOTP prompt instead_ |
| 85 | |
| 86 | [login]: https://docs.npmjs.com/cli/adduser |