Skip to main content

管理员令牌

🌐 Admin tokens

Page summary:

管理员令牌用于验证对 Strapi 管理 API 的程序化访问。每个令牌的权限范围是其所有者权限的一个子集,并设计用于自动化工作流程,例如 MCP 代理、CI/CD 管道和脚本。

管理员令牌允许自动化客户端对 Strapi 管理 API 的请求进行身份验证。若要对内容 API 的请求进行身份验证,请参见 API 令牌

🌐 Admin tokens allow automated clients to authenticate requests to the Strapi Admin API. For authenticating requests to the Content API, see API Tokens.

管理员令牌和API令牌严格分开:每种令牌在另一种令牌的路由上都会被拒绝。

🌐 Admin tokens and API tokens are strictly separated: each is rejected on the other's routes.

IDENTITY CARD
计划

免费功能

角色与权限

默认对超级管理员激活。每个更底层的角色需要在“角色 > 设置 - 管理令牌”中显式授予权限。

激活

默认可用并已激活

环境

在开发和生产环境中均可用

Admin tokens in the admin panelAdmin tokens in the admin panel

配置

🌐 Configuration

管理员令牌完全通过管理员面板进行配置。没有基于代码的配置是专门针对管理员令牌的。适用于所有令牌类型的共享盐值和加密密钥通过你在 /config/admin 文件中的 apiToken.saltapiToken.secrets.encryptionKey 设置(参见 API 令牌)。

🌐 Admin tokens are configured entirely from the admin panel. No code-based configuration is specific to Admin tokens. The shared salt and encryption key that apply to all token kinds are set via apiToken.salt and apiToken.secrets.encryptionKey in your /config/admin file (see API tokens).

配置此功能的路径: 设置 > 管理面板 > 管理员令牌

创建新的管理员令牌

🌐 Creating a new Admin token

Prerequisites

如果你不是 Strapi 实例的超级管理员,则必须由超级管理员授予你以下权限:

🌐 If you're not the Strapi instance's super admin, the super admin must have granted you the following permissions:

  • 访问管理员令牌设置页面
  • 创建(生成)管理员令牌

(详情请参见 RBAC > 配置角色权限)。

  1. 点击 创建新的管理员令牌 按钮。

  2. 在令牌创建表单中,配置新的管理员令牌:

    | 设置名称 | 操作说明 | | --- | --- | | 名称 | 填写令牌的名称。 | | 描述 | (可选)填写令牌的描述。 | | 令牌有效期 | 选择一个有效期:7天30天90天_或_无限制。 |

  3. 定义此令牌可以执行的管理员操作:

    • 点击表单下方的选项卡以浏览权限类别。
    • 使用复选框启用或禁用单独的权限。
    Note

    当前用户没有的权限会显示为禁用状态,无法选择。应用于所有者角色的条件将显示为只读,并自动应用于令牌。

  4. 点击 保存 按钮。新的管理员令牌将显示在界面顶部,并附有一个复制按钮

Admin token permissionsAdmin token permissions
Caution

明文令牌密钥仅在创建或重新生成后立即显示一次。使内容 API 令牌密钥可持久查看的 admin.secrets.encryptionKey 配置不适用于管理员令牌。管理员令牌密钥始终仅限于令牌所有者访问,无论加密配置如何。

🌐 The plaintext token key is shown only once, immediately after creation or regeneration. The admin.secrets.encryptionKey configuration that makes Content API token keys persistently viewable does not apply to Admin tokens. Admin token keys are always restricted to the token owner, regardless of encryption configuration.

管理管理员令牌

🌐 Managing Admin tokens

管理员令牌在 设置 > 管理面板 > 管理员令牌 有专门的设置页面。管理员令牌和 API 令牌存储在同一个数据库表中(通过 kind 字段区分),但在管理面板中通过独立的界面进行管理。

管理员令牌页面显示一个 所有者 列,显示每个令牌所有者的显示名称。

🌐 The Admin Tokens page displays an Owner column showing the display name of each token's owner.

任何有权限访问管理员令牌设置页面的用户都可以查看管理员令牌。令牌只能由其拥有者或超级管理员编辑或删除。

🌐 Any user with access to the Admin Tokens settings page can view Admin tokens. A token can only be edited or deleted by its owner or a super-admin.

当超级管理员查看由其他用户拥有的管理员令牌时,令牌详情面板中会出现一个只读的 Owner 字段。权限面板仅显示令牌所有者权限范围内的复选框,而不显示超级管理员的无限制访问权限。

🌐 When a super-admin views an Admin token owned by another user, a read-only Owner field appears in the token details panel. The permissions panel shows only the checkboxes within the token owner's permission scope, not the super-admin's unrestricted access.

从角色中移除权限会导致该角色用户拥有的管理员令牌自动删除相应的权限。

🌐 Removing a permission from a role causes Admin tokens owned by users of that role to have the corresponding permission deleted automatically.

Owner account deactivation and deletion
  • 如果令牌拥有者的账户被删除,该用户拥有的所有管理员令牌及其相关权限都会被自动删除。没有恢复路径。在注销拥有管理员令牌的团队成员之前,请轮换并更换管理员令牌。
  • 如果令牌所有者的账户被停用或封锁,任何使用该所有者的管理员令牌认证的请求都会被拒绝。令牌本身不会被删除。重新激活或解封账户会恢复令牌的功能。

重新生成管理员令牌

🌐 Regenerating an Admin token

重新生成按钮仅对令牌所有者可见。其他用户,包括超级管理员,无法看到他们不拥有的令牌的此按钮。

🌐 The Regenerate button is only visible to the token's owner. Other users, including super-admins, do not see this button for tokens they do not own.

要重新生成管理员令牌:

🌐 To regenerate an Admin token:

  1. 点击管理员令牌的编辑按钮。
  2. 点击 重新生成 按钮。
  3. 点击 重新生成 按钮,在对话框中确认。
  4. 复制界面顶部显示的新管理员令牌。

使用

🌐 Usage

使用管理员令牌可以以经过身份验证的用户身份在 Strapi 的管理员路由上执行请求。

🌐 Using Admin tokens allows executing a request on Strapi's admin routes as an authenticated user.

管理员令牌可以帮助在不管理用户账户的情况下为人员或应用提供访问权限,例如连接 MCP 服务器或 CI/CD 管道。

🌐 Admin tokens can be helpful to give access to people or applications without managing a user account, for instance to connect an MCP server or a CI/CD pipeline.

在对 Strapi 的管理路由执行请求时,管理员令牌应以以下语法添加到请求的 Authorization 头中:bearer your-admin-token

🌐 When performing a request to Strapi's admin routes, the Admin token should be added to the request's Authorization header with the following syntax: bearer your-admin-token.

Caution

永远不要在客户端代码中暴露管理员令牌。将它们存储在机密管理器或环境变量中。

🌐 Never expose Admin tokens in client-side code. Store them in a secrets manager or environment variable.