跳转至

认证鉴权 API

POST /api/v1/auth/login

用户登录,获取 JWT 令牌。

请求

{
  "username": "admin",
  "password": "janpnp"
}

响应

{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 259200,
  "user": {
    "id": "user_admin",
    "username": "admin",
    "display_name": "系统管理员",
    "role": "admin"
  }
}

错误

状态码 说明
400 无效的请求体
401 用户名或密码错误

POST /api/v1/auth/wechat-login

微信小程序登录。

请求

{
  "code": "微信临时登录凭证",
  "profile": {
    "nickName": "用户昵称",
    "avatarUrl": "https://example.com/avatar.png"
  }
}

响应

{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 259200,
  "user": {
    "id": "wechat_abc123...",
    "username": "wechat_abc123...",
    "display_name": "用户昵称",
    "avatar_url": "https://example.com/avatar.png",
    "role": "wechat",
    "provider": "wechat"
  }
}

错误

状态码 说明
400 缺少微信登录凭证
401 微信登录凭证无效
502 微信服务不可用
503 微信登录未配置

POST /api/v1/auth/refresh

刷新 JWT 令牌(需要携带有效令牌)。

请求头

Authorization: Bearer <token>

响应

{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "user": {
    "id": "user_admin",
    "username": "admin",
    "display_name": "系统管理员",
    "role": "admin"
  }
}

错误

状态码 说明
401 未认证

说明

令牌有效期

默认 72 小时,可通过环境变量 CLOUD_JWT_EXPIRE_HOURS 配置。

用户管理

用户通过 CLOUD_AUTH_USERS 环境变量以 JSON 格式配置:

{
  "admin": {
    "password": "strong-password",
    "role": "admin",
    "display_name": "系统管理员"
  },
  "operator": {
    "password": "operator-password",
    "role": "user",
    "display_name": "操作员"
  }
}

内置用户

默认配置包含管理员用户 admin,密码为 janpnp生产环境必须修改)。