You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`apiToken.salt`| Salt used to generate [API tokens](/cms/features/api-tokens)| string | Random string |
27
+
|`apiToken.secrets.encryptionKey`| Encryption key used to set [API tokens visibility](/cms/features/api-tokens#ensuring-api-tokens-are-visible-in-the-admin-panel) in the admin panel | string | Random string |
27
28
|`auditLogs.enabled`| Enable or disable the [Audit Logs](/cms/features/audit-logs) feature | boolean |`true`|
28
29
|`auditLogs.retentionDays`| How long [Audit Logs](/cms/features/audit-logs) are kept, in days.<br /><br />_The behavior differs for self-hosted vs. Strapi Cloud customers, see the note under the table._| integer | 90 |
@@ -47,42 +47,44 @@ Most configuration options for API tokens are available in the admin panel, and
47
47
48
48
### Admin panel settings
49
49
50
-
**Path to configure the feature:** <Iconname="gear-six" /> *Settings > Global settings > API Tokens*
50
+
**Path to configure the feature:** <Iconname="gear-six" /> _Settings > Global settings > API Tokens_
51
51
52
-
The *API Tokens* interface displays a table listing all of the created API tokens. More specifically, it displays each API token's name, description, date of creation, and date of last use.
52
+
The _API Tokens_ interface displays a table listing all of the created API tokens. More specifically, it displays each API token's name, description, date of creation, and date of last use.
53
53
54
54
From there, you have the possibility to:
55
55
56
56
- click on the <Iconname="pencil-simple" /> to edit an API token's name, description, type, duration or [regenerate the token](#regenerating-an-api-token).
57
57
- click on the <Iconname="trash" /> to delete an API token.
58
58
59
59
:::note
60
-
Strapi pre-generates 2 API tokens for you, a Full access one and a Read-only one. Since tokens can be only seen once after creation, you have to [regenerate](#regenerating-an-api-token) them before using them.
60
+
Strapi pre-generates 2 API tokens for you, a Full access one and a Read-only one. Since tokens can be only seen once without encryption configured, you may want to [regenerate](#regenerating-an-api-token) them after setting up an encryption key to make them permanently viewable.
61
61
:::
62
62
63
63
#### Creating a new API token
64
64
65
65
1. Click on the **Create new API Token** button.
66
66
2. In the API token edition interface, configure the new API token:
| Description | (optional) Write a description for the API token.|
71
-
| Token duration | Choose a token duration: *7 days*, *30 days*, *90 days*, or *Unlimited*. |
72
-
| Token type | Choose a token type: *Read-only*, *Full access*, or *Custom*. |
73
-
3. (optional) For the *Custom* token type, define specific permissions for your API endpoints by clicking on the content-type name and using checkboxes to enable or disable permissions.
| Description | (optional) Write a description for the API token. |
71
+
| Token duration | Choose a token duration: _7 days_, _30 days_, _90 days_, or _Unlimited_. |
72
+
| Token type | Choose a token type: _Read-only_, _Full access_, or _Custom_.|
73
+
3. (optional) For the _Custom_ token type, define specific permissions for your API endpoints by clicking on the content-type name and using checkboxes to enable or disable permissions.
74
74
4. Click on the **Save** button. The new API token will be displayed at the top of the interface, along with a copy button <Iconname="copy" />.
For security reasons, API tokens are only shown right after they have been created. When refreshing the page or navigating elsewhere in the admin panel, the newly created API token will be hidden and will not be displayed again.
84
+
:::info Viewable tokens
85
+
If an encryption key is configured in your Strapi project (`admin.secrets.encryptionKey`), the newly created and regenerated API tokens will be **viewable at any time** in the admin panel.
86
+
87
+
If no encryption key is set, tokens will only be viewable **once**, immediately after creation or regeneration.
86
88
:::
87
89
88
90
#### Regenerating an API token
@@ -98,13 +100,51 @@ New API tokens are generated using a salt. This salt is automatically generated
98
100
99
101
The salt can be customized:
100
102
101
-
- either by updating the string value for `apiToken.salt` in `./config/admin.js` (see [admin panel configuration documentation](/cms/configurations/admin-panel))
103
+
- either by updating the string value for `apiToken.salt` in [your `/config/admin` file](/cms/configurations/admin-panel)
102
104
- or by creating an `API_TOKEN_SALT`[environment variable](/cms/configurations/environment#strapi) in the `.env` file of the project
103
105
104
106
:::caution
105
107
Changing the salt invalidates all the existing API tokens.
106
108
:::
107
109
110
+
#### Ensuring API tokens are visible in the admin panel
111
+
112
+
To allow persistent visibility of API tokens in the admin panel, an encryption key must be provided in [your `/config/admin` file](/cms/configurations/admin-panel) under `apiToken.secrets.encryptionKey`:
113
+
114
+
<TabsgroupId="js-ts">
115
+
<TabItemlabel="JavaScript"value="js">
116
+
117
+
```js title="/config/admin.js"
118
+
module.exports= ({ env }) => ({
119
+
// other config parameters
120
+
apiToken: {
121
+
secrets: {
122
+
encryptionKey:env('ENCRYPTION_KEY'),
123
+
},
124
+
}
125
+
});
126
+
```
127
+
128
+
</TabItem>
129
+
130
+
<TabItemlabel="TypeScript"value="ts">
131
+
132
+
```js title="/config/admin.ts"
133
+
exportdefault ({ env }) => ({
134
+
// other config parameters
135
+
apiToken: {
136
+
secrets: {
137
+
encryptionKey:env('ENCRYPTION_KEY'),
138
+
},
139
+
}
140
+
});
141
+
```
142
+
143
+
</TabItem>
144
+
</Tabs>
145
+
146
+
This key is used to encrypt and decrypt token values. Without this key, tokens remain usable, but will not be viewable after initial display. New Strapi projects will have this key automatically generated.
147
+
108
148
## Usage
109
149
110
150
Using API tokens allows executing a request on [REST API](/cms/api/rest) or [GraphQL API](/cms/api/graphql) endpoints as an authenticated user.
0 commit comments