认证

登录、注册、Token 刷新与个人资料接口。

认证流程

MERMAID
Mermaid 图表加载中...

登录

Endpoint

POST · /api/v1/auth/login

无需认证。成功时返回一对 Access/Refresh Token,并在 Cookie 中写入 access_token

请求

JSON
{
  "username": "alice",
  "password": "secret123"
}
字段类型必填说明
usernamestring用户名或邮箱
passwordstring密码

响应

JSON
{
  "code": 0,
  "message": "success",
  "data": {
    "access_token": "eyJhbGciOi...",
    "refresh_token": "eyJhbGciOi...",
    "expires_in": 7200,
    "token_type": "Bearer",
    "user": {
      "id": "uuid",
      "username": "alice",
      "email": "alice@example.com",
      "role": "user",
      "password_must_change": false
    }
  }
}

错误

Code条件
40100用户名或密码错误
40100账号已被禁用

注册

Endpoint

POST · /api/v1/auth/register

仅当 allow_registration = true 时可用。

请求

JSON
{
  "username": "bob",
  "email": "bob@example.com",
  "password": "strong-pass"
}
字段约束
username3-32 字符
emailRFC 邮箱
password6-64 字符

错误

Code条件
40300注册已关闭
40900用户名/邮箱已存在

刷新 Token

Endpoint

POST · /api/v1/auth/refresh

使用 Refresh Token 换取新的 Access Token,无需再次登录。

请求

JSON
{
  "refresh_token": "eyJhbGciOi..."
}

响应

响应格式与登录相同,返回全新的 Access/Refresh Token 对。

登出

Endpoint

POST · /api/v1/auth/logout · 需认证

使当前 Token 失效并清除 Cookie。

JSON
{ "code": 0, "message": "success", "data": null }

获取个人资料

Endpoint

GET · /api/v1/profile · 需认证

响应

JSON
{
  "code": 0,
  "data": {
    "id": "uuid",
    "username": "alice",
    "nickname": "Alice",
    "email": "alice@example.com",
    "avatar_url": "https://...",
    "role": "user",
    "storage_limit": 10737418240,
    "storage_used": 521308864,
    "is_active": true,
    "created_at": "2026-01-01T00:00:00Z"
  }
}

更新个人资料

Endpoint

PUT · /api/v1/profile · 需认证

请求

JSON
{
  "nickname": "Alice Liu",
  "email": "alice@new.example.com",
  "avatar_url": "https://..."
}

所有字段可选,仅传入想修改的字段。

修改密码

Endpoint

POST · /api/v1/auth/change-password · 需认证

请求

JSON
{
  "old_password": "secret123",
  "new_password": "stronger-pass"
}

首次登录重置

Endpoint

POST · /api/v1/auth/first-login-reset · 需认证

专用于默认管理员首次登录后修改用户名与密码。调用成功后 password_must_change 置为 false

请求

JSON
{
  "username": "real-admin",
  "email": "admin@your-domain.com",
  "password": "strong-new-password"
}
注意

默认 admin/admin 账号在完成此重置前,无法访问任何业务接口。

Token 生命周期

类型默认有效期刷新方式
Access Token2 小时POST /auth/refresh
Refresh Token7 天重新登录
API Token永不过期或自定义管理

JWT 密钥存放在 settings.jwt_secret,首次启动自动生成。

下一步