Skip to content

Commit 2c510df

Browse files
authored
npm-granular-access-token (#33)
1 parent d67fde7 commit 2c510df

File tree

13 files changed

+229
-60
lines changed

13 files changed

+229
-60
lines changed

content/cli/v7/commands/npm-token.md

+35-13
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,41 @@ redirect_from:
2020
---
2121

2222
### Synopsis
23+
24+
<!-- AUTOGENERATED USAGE DESCRIPTIONS START -->
25+
<!-- automatically generated, do not edit manually -->
26+
<!-- see lib/commands/token.js -->
27+
2328
```bash
2429
npm token list [--json|--parseable]
2530
npm token create [--read-only] [--cidr=1.1.1.1/24,2.2.2.2/16]
2631
npm token revoke <id|token>
2732
```
2833

29-
Note: This command is unaware of workspaces.
34+
<!-- automatically generated, do not edit manually -->
35+
<!-- see lib/commands/token.js -->
36+
37+
<!-- AUTOGENERATED USAGE DESCRIPTIONS END -->
38+
39+
<Note>
40+
41+
**Note:** This command is unaware of workspaces.
42+
43+
</Note>
3044

3145
### Description
3246

33-
This lets you list, create and revoke authentication tokens.
47+
This command lets you:
48+
49+
* List all authentication tokens
50+
* Revoke any authentication token
51+
* Generate personal access tokens
52+
53+
<Note>
54+
55+
**Note:** To generate granular access tokens, you must use the website. For more information, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
56+
57+
</Note>
3458

3559
* `npm token list`:
3660
Shows a table of all active authentication tokens. You can request
@@ -64,10 +88,8 @@ This lets you list, create and revoke authentication tokens.
6488
your password, and, if you have two-factor authentication enabled, an
6589
otp.
6690

67-
Currently, the cli can not generate automation tokens. Please refer to
68-
the [docs
69-
website](https://docs.npmjs.com/creating-and-viewing-access-tokens)
70-
for more information on generating automation tokens.
91+
The CLI cannot generate automation tokens or granular access tokens. For more information on generating tokens, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
92+
.
7193

7294
```bash
7395
+----------------+--------------------------------------+
@@ -144,10 +166,10 @@ password, npm will prompt on the command line for one.
144166

145167
### See Also
146168

147-
* [npm adduser](/cli/v7/commands/npm-adduser)
148-
* [npm registry](/cli/v7/using-npm/registry)
149-
* [npm config](/cli/v7/commands/npm-config)
150-
* [npmrc](/cli/v7/configuring-npm/npmrc)
151-
* [npm owner](/cli/v7/commands/npm-owner)
152-
* [npm whoami](/cli/v7/commands/npm-whoami)
153-
* [npm profile](/cli/v7/commands/npm-profile)
169+
* [npm adduser](/commands/npm-adduser)
170+
* [npm registry](/using-npm/registry)
171+
* [npm config](/commands/npm-config)
172+
* [npmrc](/configuring-npm/npmrc)
173+
* [npm owner](/commands/npm-owner)
174+
* [npm whoami](/commands/npm-whoami)
175+
* [npm profile](/commands/npm-profile)

content/cli/v8/commands/npm-token.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,30 @@ npm token revoke <id|token>
2727
npm token create [--read-only] [--cidr=list]
2828
```
2929

30-
Note: This command is unaware of workspaces.
30+
<!-- automatically generated, do not edit manually -->
31+
<!-- see lib/commands/token.js -->
32+
33+
<!-- AUTOGENERATED USAGE DESCRIPTIONS END -->
34+
35+
<Note>
36+
37+
**Note:** This command is unaware of workspaces.
38+
39+
</Note>
3140

3241
### Description
3342

34-
This lets you list, create and revoke authentication tokens.
43+
This command lets you:
44+
45+
* List all authentication tokens
46+
* Revoke any authentication token
47+
* Generate personal access tokens
48+
49+
<Note>
50+
51+
**Note:** To generate granular access tokens, you must use the website. For more information, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
52+
53+
</Note>
3554

3655
* `npm token list`:
3756
Shows a table of all active authentication tokens. You can request
@@ -65,10 +84,8 @@ This lets you list, create and revoke authentication tokens.
6584
your password, and, if you have two-factor authentication enabled, an
6685
otp.
6786

68-
Currently, the cli can not generate automation tokens. Please refer to
69-
the [docs
70-
website](https://docs.npmjs.com/creating-and-viewing-access-tokens)
71-
for more information on generating automation tokens.
87+
The CLI cannot generate automation tokens or granular access tokens. For more information on generating tokens, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
88+
.
7289

7390
```bash
7491
+----------------+--------------------------------------+
@@ -128,10 +145,10 @@ password, npm will prompt on the command line for one.
128145

129146
### See Also
130147

131-
* [npm adduser](/cli/v8/commands/npm-adduser)
132-
* [npm registry](/cli/v8/using-npm/registry)
133-
* [npm config](/cli/v8/commands/npm-config)
134-
* [npmrc](/cli/v8/configuring-npm/npmrc)
135-
* [npm owner](/cli/v8/commands/npm-owner)
136-
* [npm whoami](/cli/v8/commands/npm-whoami)
137-
* [npm profile](/cli/v8/commands/npm-profile)
148+
* [npm adduser](/commands/npm-adduser)
149+
* [npm registry](/using-npm/registry)
150+
* [npm config](/commands/npm-config)
151+
* [npmrc](/configuring-npm/npmrc)
152+
* [npm owner](/commands/npm-owner)
153+
* [npm whoami](/commands/npm-whoami)
154+
* [npm profile](/commands/npm-profile)

content/cli/v9/commands/npm-token.md

+51-13
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,40 @@ redirect_from:
3737

3838
### Synopsis
3939

40+
<!-- AUTOGENERATED USAGE DESCRIPTIONS START -->
41+
<!-- automatically generated, do not edit manually -->
42+
<!-- see lib/commands/token.js -->
43+
4044
```bash
4145
npm token list
4246
npm token revoke <id|token>
4347
npm token create [--read-only] [--cidr=list]
4448
```
4549

46-
Note: This command is unaware of workspaces.
50+
<!-- automatically generated, do not edit manually -->
51+
<!-- see lib/commands/token.js -->
52+
53+
<!-- AUTOGENERATED USAGE DESCRIPTIONS END -->
54+
55+
<Note>
56+
57+
**Note:** This command is unaware of workspaces.
58+
59+
</Note>
4760

4861
### Description
4962

50-
This lets you list, create and revoke authentication tokens.
63+
This command lets you:
64+
65+
* List all authentication tokens
66+
* Revoke any authentication token
67+
* Generate legacy tokens
68+
69+
<Note>
70+
71+
**Note:** To generate granular access tokens, you must use the website. For more information, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
72+
73+
</Note>
5174

5275
* `npm token list`:
5376
Shows a table of all active authentication tokens. You can request
@@ -81,10 +104,8 @@ This lets you list, create and revoke authentication tokens.
81104
your password, and, if you have two-factor authentication enabled, an
82105
otp.
83106

84-
Currently, the cli can not generate automation tokens. Please refer to
85-
the [docs
86-
website](https://docs.npmjs.com/creating-and-viewing-access-tokens)
87-
for more information on generating automation tokens.
107+
The CLI cannot generate automation tokens or granular access tokens. For more information on generating tokens, see "[Creating and viewing access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens)."
108+
.
88109

89110
```bash
90111
+----------------+--------------------------------------+
@@ -108,6 +129,9 @@ This lets you list, create and revoke authentication tokens.
108129

109130
### Configuration
110131

132+
<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->
133+
<!-- automatically generated, do not edit manually -->
134+
<!-- see lib/utils/config/definitions.js -->
111135
#### `read-only`
112136

113137
* Default: false
@@ -116,6 +140,9 @@ This lets you list, create and revoke authentication tokens.
116140
This is used to mark a token as unable to publish when configuring limited
117141
access tokens with the `npm token create` command.
118142

143+
<!-- automatically generated, do not edit manually -->
144+
<!-- see lib/utils/config/definitions.js -->
145+
119146
#### `cidr`
120147

121148
* Default: null
@@ -124,13 +151,19 @@ access tokens with the `npm token create` command.
124151
This is a list of CIDR address to be used when configuring limited access
125152
tokens with the `npm token create` command.
126153

154+
<!-- automatically generated, do not edit manually -->
155+
<!-- see lib/utils/config/definitions.js -->
156+
127157
#### `registry`
128158

129159
* Default: "https://registry.npmjs.org/"
130160
* Type: URL
131161

132162
The base URL of the npm registry.
133163

164+
<!-- automatically generated, do not edit manually -->
165+
<!-- see lib/utils/config/definitions.js -->
166+
134167
#### `otp`
135168

136169
* Default: null
@@ -142,12 +175,17 @@ when publishing or changing package permissions with `npm access`.
142175
If not set, and a registry response fails with a challenge for a one-time
143176
password, npm will prompt on the command line for one.
144177

178+
<!-- automatically generated, do not edit manually -->
179+
<!-- see lib/utils/config/definitions.js -->
180+
181+
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
182+
145183
### See Also
146184

147-
* [npm adduser](/cli/v9/commands/npm-adduser)
148-
* [npm registry](/cli/v9/using-npm/registry)
149-
* [npm config](/cli/v9/commands/npm-config)
150-
* [npmrc](/cli/v9/configuring-npm/npmrc)
151-
* [npm owner](/cli/v9/commands/npm-owner)
152-
* [npm whoami](/cli/v9/commands/npm-whoami)
153-
* [npm profile](/cli/v9/commands/npm-profile)
185+
* [npm adduser](/commands/npm-adduser)
186+
* [npm registry](/using-npm/registry)
187+
* [npm config](/commands/npm-config)
188+
* [npmrc](/configuring-npm/npmrc)
189+
* [npm owner](/commands/npm-owner)
190+
* [npm whoami](/commands/npm-whoami)
191+
* [npm profile](/commands/npm-profile)

content/integrations/integrating-npm-with-external-services/about-access-tokens.mdx

+35-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,50 @@ redirect_from:
1313

1414
An access token is an alternative to using your username and password for authenticating to npm when using the API or the npm command-line interface (CLI). An access token is a hexadecimal string that you can use to authenticate, and which gives you the right to install and/or publish your modules.
1515

16-
The npm CLI automatically generates an access token for you when you run `npm login`. You can also create an access token to give other tools (such as continuous integration testing environments) access to your npm packages. For example, GitHub Actions provides the ability to store [secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets), like access tokens, that you can then use to authenticate. When your workflow runs, it will be able to complete npm tasks as you, including installing private packages you can access.
16+
There are two types of access tokens available:
17+
18+
* [Legacy tokens](#about-legacy-tokens)
19+
* [Granular access tokens](#about-granular-access-tokens)
20+
21+
You can create access tokens to give other tools (such as continuous integration testing environments) access to your npm packages. For example, GitHub Actions provides the ability to store [secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets), such as access tokens, that you can then use to authenticate. When your workflow runs, it will be able to complete npm tasks as you, including installing private packages you can access.
1722

1823
You can work with tokens from the web or the CLI, whichever is easiest. What you do in each environment will be reflected in the other environment.
1924

2025
npm token commands let you:
2126

2227
* View tokens for easier tracking and management
23-
* Create new tokens, specifying read-only or full-permission
28+
* Create new legacy tokens
2429
* Limit access according to IP address ranges (CIDR)
2530
* Delete/revoke tokens
2631

2732
For more information on creating and viewing access tokens on the web and CLI, see "[Creating and viewing access tokens][create-token]".
2833

29-
[create-token]: creating-and-viewing-access-tokens
34+
## About legacy tokens
35+
36+
Legacy tokens are created with the same permissions as the user who created them. The npm CLI automatically generates and uses a publish token when you run `npm login`.
37+
38+
There are three different types of legacy tokens:
39+
40+
41+
* **Read-only**: You can use these tokens to download packages from the registry. These tokens are best for automation and workflows where you are installing packages. For greater security, we recommend using [granular access tokens](#about-granular-access-tokens) instead.
42+
* **Automation**: You can use these tokens to download packages and install new ones. These tokens are best for automation workflows where you are publishing new packages. Automation tokens do not 2FA for executing operations on npm and are suitable for CI/CD workflows. For greater security, we recommend using [granular access tokens](#about-granular-access-tokens) instead.
43+
* **Publish**: You can use these tokens to download packages, install packages, and update user and package settings. We recommend using them for interactive workflows such as a CLI. If 2FA is enabled on your account, publish tokens will require 2FA to execute sensitive operations on npm.
3044

45+
Legacy tokens do not have an expiration date. It is important to be aware of your tokens and keep them protected for account security. For more information, see "[Securing your token][secure-token]."
46+
47+
## About granular access tokens
48+
49+
Granular access tokens allow you to restrict access provided to the token based on what you want to use the token for. With granular access tokens, you can:
50+
51+
* Restrict which packages and scopes a token has access to
52+
* Grant tokens access to specific organizations
53+
* Set a token expiration date
54+
* Limit token access based on IP address ranges
55+
* Select between **read-only** or **read and write** access
56+
57+
You can create up to 50 granular access tokens on your npm account. You can set how long your token is valid for, up to a maximum expiration of 365 days from creation. Each token can access up to 50 organizations, and up to either 50 packages, 50 scopes, or a combination of 50 packages and scopes. Access tokens are tied to users’ permission; hence it cannot have more permission than the user at any point in time. If a user has their access revoked from a package or an org., their granular access token also will have its access revoked from those packages or org.
58+
59+
When you give a token access to an organization, the token can only be used for managing organization settings and teams or users associated with the organization. It does not give the token the right to publish packages managed by the organization.
60+
61+
[create-token]: creating-and-viewing-access-tokens
62+
[secure-token]: using-private-packages-in-a-ci-cd-workflow#securing-your-token

0 commit comments

Comments
 (0)