API 参考

所有 API 端点的完整参考文档。

OAuth 端点

GET /oauth/authorize

OAuth 授权页面 — 跳转用户到登录/授权

POST /oauth/token

用授权码换取 Token(支持 PKCE);刷新 Token 时旧 Token 立即失效(Rotation)

GET /oauth/userinfo

获取当前用户信息(Bearer Token)

GET /oauth/subscription

获取用户套餐和配额(比 userinfo 更轻量,仅平台第一方客户端)

GET /oauth/app-quotas

获取用户 workspace 的 per-app 配额(支持 ?client_id= 过滤,仅平台第一方客户端)

GET /oauth/identities

获取用户所有关联的 OAuth 身份

POST /oauth/revoke

撤销 refresh token;access token 若带 sid 会立即失效(销毁对应 session)

GET /oauth/logout

SSO 联合退出,清除 session。跨域回跳需同时提供 post_logout_redirect_uri + client_id 且 URI 必须精确匹配注册值

UserInfo 响应格式

{
  "sub": "user_id",
  "email": "user@example.com",
  "email_verified": true,
  "name": "User Name",
  "picture": "https://...",
  "login": "github_username",
  "orcid_id": "0000-0002-xxxx",
  "role": "user",
  "is_platform_admin": false,
  "tier": "free",
  "workspace": {
    "id": "ws_personal_xxx",
    "name": "My Workspace",
    "type": "personal",
    "role": "owner",
    "tier": "free"
  },
  "quotas": {},
  "workspaces": [
    { "id": "ws_personal_xxx", "name": "My Workspace", "type": "personal", "role": "owner", "tier": "free" }
  ],
  "id": "user_id",
  "uid": "user-a1b2c3d4",
  "created_at": "2026-01-15T08:30:00.000Z",
  "updated_at": "2026-02-04T10:15:00.000Z"
}
💡 orcid_id 字段
仅当用户绑定了 ORCID 账号时返回 ORCID iD,否则为 null。
⚠️ scope 决定返回哪些字段
email scope 控制邮箱字段,profile scope 控制基础资料字段。workspace / quotas / platform_admin 这组内部字段仅平台第一方客户端可见,普通第三方客户端不会拿到这些 claims。
💡 内部端点边界
/oauth/subscription 与 /oauth/app-quotas 仅平台第一方客户端可访问;第三方客户端应使用标准 /oauth/userinfo + 自己的应用会话模型。

Workspace API

GET /api/workspaces

列出用户所有 workspace

POST /api/workspaces

创建新 workspace

POST /api/workspaces/:id/invitations

邀请用户加入 workspace

GET /api/workspaces/:id/invitations

列出 workspace 的待处理邀请

DELETE /api/workspaces/:id/invitations/:inviteId

取消邀请

Mail API

💡 平台基础服务
W-ID Mail 通过 /api/mail/* 暴露给平台产品使用。业务产品应复用 W-ID 的 OAuth client、workspace 和 scope,不要自行实现独立邮箱账号体系。
# OAuth access token
Authorization: Bearer ACCESS_TOKEN

# 或 workspace API key
Authorization: Bearer 

# Team workspace 建议显式带 workspace_id
GET /api/mail/threads?workspace_id=ws_team_xxx
POST /api/mail/send

发送 workspace 邮件。需要 mail.send 或 mail.manage。

GET /api/mail/threads

列出 workspace 线程。需要 mail.read / mail.reply / mail.manage。

GET /api/mail/threads/:id

读取单个线程及消息。

POST /api/mail/threads/:id/reply

回复线程。需要 mail.reply 或 mail.manage。

GET /api/mail/messages/:id

读取单条邮件消息。

GET /api/mail/deliveries

读取投递任务。需要 mail.delivery.read 或 mail.manage。

GET /api/mail/deliveries/:id

读取单个投递任务。

GET /api/mail/domains

读取 workspace 邮件域名。需要 owner/admin + mail.settings.read / mail.settings.write / mail.manage。

GET /api/mail/addresses

读取 workspace 邮件地址。需要 owner/admin + 邮件设置 scope。

Mail Scopes

mail.send
mail.read
mail.reply
mail.delivery.read
mail.settings.read
mail.settings.write
mail.manage

Send Mail Example

POST /api/mail/send?workspace_id=ws_team_xxx
Authorization: Bearer ACCESS_TOKEN
Idempotency-Key: email_launch_2026_04_19_001
Content-Type: application/json

{
  "from": "hello@platform.example",
  "to": ["user@example.com", "ops@example.com"],
  "cc": "lead@example.com",
  "bcc": ["audit@example.com"],
  "reply_to": "support@platform.example",
  "subject": "Workspace alert",
  "html": "<p>Hello from W-ID Mail</p>",
  "headers": {
    "X-Entity-Ref-ID": "launch-2026-04-19"
  },
  "tags": {
    "environment": "production"
  }
}

from 必须是当前 workspace 已接管、启用且已验证的邮件地址。返回体会直接给出 delivery_id 和 provider message id,方便继续查询 /api/mail/deliveries/:id。

cURL Example

curl --request POST 'https://auth.vibe.wang/api/mail/send?workspace_id=ws_team_xxx'   --header "Authorization: Bearer $ACCESS_TOKEN"   --header 'Content-Type: application/json'   --header 'Idempotency-Key: email_launch_2026_04_19_001'   --data '{
    "from": "hello@platform.example",
    "to": ["user@example.com", "ops@example.com"],
    "cc": "lead@example.com",
    "bcc": ["audit@example.com"],
    "reply_to": "support@platform.example",
    "subject": "Workspace alert",
    "html": "<p>Hello from W-ID Mail</p>",
    "headers": {
      "X-Entity-Ref-ID": "launch-2026-04-19"
    },
    "tags": {
      "environment": "production"
    }
  }'

TypeScript Example

const response = await fetch('https://auth.vibe.wang/api/mail/send?workspace_id=ws_team_xxx', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer ACCESS_TOKEN',
    'Content-Type': 'application/json',
    'Idempotency-Key': 'email_launch_2026_04_19_001',
  },
  body: JSON.stringify({
    from: 'hello@platform.example',
    to: ['user@example.com', 'ops@example.com'],
    cc: 'lead@example.com',
    bcc: ['audit@example.com'],
    reply_to: 'support@platform.example',
    subject: 'Workspace alert',
    html: '<p>Hello from W-ID Mail</p>',
    headers: {
      'X-Entity-Ref-ID': 'launch-2026-04-19',
    },
    tags: {
      environment: 'production',
    },
  }),
});

const email = await response.json();

Mail 错误格式

{
  "error": "invalid_scope",
  "message": "The OAuth token is missing the required mail scope for this operation.",
  "requiredScopes": ["mail.read", "mail.reply", "mail.manage"]
}

常见错误码:workspace_required、invalid_scope、forbidden、not_found、mail_send_failed、mail_reply_failed。

Publications API

GET /api/publications/me

获取当前用户的 ORCID 论文列表

GET /api/publications/:orcid_id

按 ORCID ID 公开查询论文(无需 Token)