个人 API 令牌
个人访问令牌(PAT)允许你在不使用密码的情况下对 Forgexa API 进行认证。令牌支持作用域、轮换和单独撤销。
列出令牌
返回当前用户的所有活跃和已撤销的令牌。
http
GET /api/v1/users/me/api-tokens
Authorization: Bearer <token>响应 200 OK
json
[
{
"id": "uuid",
"name": "CI Pipeline",
"token_prefix": "pat_abc1",
"scopes": ["read", "write"],
"is_active": true,
"last_used_at": "2026-05-15T14:30:00Z",
"expires_at": "2026-08-14T00:00:00Z",
"revoked_at": null,
"created_at": "2026-05-16T00:00:00Z"
}
]创建令牌
创建新的个人访问令牌。完整的令牌值 仅在响应中返回一次 — 请安全存储。
http
POST /api/v1/users/me/api-tokens
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "CI Pipeline",
"scopes": ["read", "write"],
"expires_in_days": 90
}响应 201 Created
json
{
"id": "uuid",
"name": "CI Pipeline",
"token": "pat_a1b2c3d4e5f6...",
"token_prefix": "pat_a1b2",
"scopes": ["read", "write"],
"expires_at": "2026-08-14T00:00:00Z",
"created_at": "2026-05-16T00:00:00Z"
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | string | 是 | 令牌的可读名称 |
scopes | string[] | 否 | 权限作用域(默认:全部) |
expires_in_days | int | 否 | 过期天数,1–365(默认:90) |
WARNING
token 字段仅在创建时返回。请立即复制并安全存储 — 之后无法再次获取。每个用户最多 10 个活跃令牌。
撤销令牌
永久撤销令牌。已撤销的令牌不可重新激活。
http
DELETE /api/v1/users/me/api-tokens/{token_id}
Authorization: Bearer <token>响应 204 No Content