认证

用用户名密码换取 Bearer JWT,所有受保护接口都靠它。含 token 刷新与当前用户信息。

DCG 使用 Bearer JWT 认证。先用账号密码登录拿到 access_token,之后每个请求带上它。

登录

text
POST /api/v1/auth/login

无需认证。

请求体

字段类型必填说明
usernamestring用户名
passwordstring密码

响应

字段类型说明
access_tokenstring访问令牌,放进 Authorization
refresh_tokenstring刷新令牌,过期时换新的 access_token
token_typestring固定为 bearer
expires_inintaccess_token 有效期(秒)

示例

bash
curl -X POST https://your-dcg-host/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"your-password"}'
json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "bearer",
  "expires_in": 3600
}

带上 token

之后所有受保护接口,把 access_token 放进请求头:

bash
curl https://your-dcg-host/api/v1/datasources \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
令牌过期

access_token 过期后请求会返回 401。用 refresh_tokenPOST /auth/refresh 换一个新的,不要让用户重新登录。

刷新令牌

text
POST /api/v1/auth/refresh

请求体:{ "refresh_token": "..." },返回新的 access_token / refresh_token / expires_in

当前用户

text
GET /api/v1/auth/me

需认证。返回当前用户的身份与权限:

字段类型说明
idUUID用户 ID
usernamestring用户名
emailstring邮箱
rolesarray角色列表,每项含 rolescope
permissionsarray<string>权限点
sku_tierstring当前授权档位(见 许可状态
提示

角色决定接口权限:superadmin / admin / dba / operator / classifier_owner / observerobserver 只读,不能确认分级。