/admin/tenants/{tenant_id}/api-keys
为指定租户创建 API Key,返回完整 key(仅显示一次),用于外部系统集成。参考:NIST SP 800-53 AC-2 (Account Management)
请求参数
| 名称 | 位置 | 类型 | 必填 | 默认值 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|---|---|
tenant_id |
path |
string |
是 | 租户ID |
请求体
Schema: service-tenant/internal/handler/dto.CreateApiKeyRequest
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
name |
string |
是 | HR系统同步 |
||
scope |
string |
否 | admin |
响应
| 状态 | 描述 | Schema |
|---|---|---|
| 201 | API Key创建成功 | dto.DataResponse-service-tenant/internal/handler/dto/CreateApiKeyResponse |
| 400 | 请求参数错误 | service-core/base/dto.SimpleResponse |
| 401 | 未认证 | service-core/base/dto.SimpleResponse |
| 403 | 权限不足 | service-core/base/dto.SimpleResponse |
| 409 | API Key名称冲突 | service-core/base/dto.SimpleResponse |
| 500 | 服务器内部错误 | service-core/base/dto.SimpleResponse |
引用的 Schema
dto.DataResponse-service-tenant/internal/handler/dto/CreateApiKeyResponse
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
code |
integer |
否 | |||
data |
service-tenant/internal/handler/dto.CreateApiKeyResponse |
否 | |||
message |
string |
否 | |||
timestamp |
string |
否 |
service-core/base/dto.SimpleResponse
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
code |
integer |
否 | |||
message |
string |
否 | |||
timestamp |
string |
否 |
service-tenant/internal/handler/dto.CreateApiKeyResponse
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
api_key |
string |
否 | tk_a1b2c3d4e5f6... |
||
created_at |
string |
否 | 2026-05-12T10:00:00Z |
||
id |
string |
否 | tak_001 |
||
key_prefix |
string |
否 | tk_a1b2c3d4 |
||
message |
string |
否 | 请立即保存API Key,关闭后无法再次查看完整Key |
||
name |
string |
否 | HR系统同步 |
||
scope |
string |
否 | admin |