v1account 上下文
账户资料
GET /v1/account/me 与 PATCH /v1/account/me:字段表、更新语义与约束。
/v1/account/me 是账号自己的扩展档案。身份字段来自 auth,扩展档案归 account,响应里分成两段而不是摊平——合并成一层会让「这个字段归哪个上下文」在接口契约里彻底消失。
GET /me
curl 'https://id.example.com/v1/account/me' \
-H "Authorization: Bearer $ACCOUNT_ACCESS_TOKEN"{
"success": true,
"sub": "usr_...",
"username": "alice",
"display_name": "Alice",
"email": "[email protected]",
"email_verified": true,
"created_at": "2026-01-04T10:00:00.000Z",
"profile": {
"gender": "female",
"birthdate": "1994-03-08",
"age": 32,
"locale": "zh-Hans",
"timezone": "Asia/Shanghai",
"bio": "Hello",
"metadata": {}
}
}| 字段 | 归属 | 说明 |
|---|---|---|
sub | auth | 用户唯一标识 |
username | auth | 用户名,可为 null |
display_name | auth | 展示名 |
email / email_verified | auth | 主邮箱与其验证状态 |
created_at | auth | 账号创建时间 |
profile.gender | account | 性别,可空 |
profile.birthdate | account | 生日,YYYY-MM-DD,可空 |
profile.age | account | 由生日推导的年龄,只读,可空 |
profile.locale | account | 语言偏好,可空 |
profile.timezone | account | 时区,可空 |
profile.bio | account | 简介,最长 2000 字符 |
profile.metadata | account | 自定义键值,写入受上限约束 |
PATCH /me
局部更新:省略的字段保持不变,显式传 null 表示清空。
| 参数 | 类型 | 说明 |
|---|---|---|
gender | string | null | 1–32 字符 |
birthdate | string | null | YYYY-MM-DD,必须是真实存在的日期 |
locale | string | null | 1–35 字符 |
timezone | string | null | 1–64 字符 |
bio | string | null | 最长 2000 字符 |
metadata | object | 键 1–64 字符,最多 32 个键,序列化后不超过 4096 字节 |
curl -X PATCH 'https://id.example.com/v1/account/me' \
-H "Authorization: Bearer $ACCOUNT_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"bio":"Hello","timezone":"Asia/Shanghai"}'未知字段会被拒绝
请求体是严格模式:出现未声明的字段会报错,而不是静默忽略。PATCH 里多出来的键通常意味着客户端拼错了名字,忽略掉会让用户以为改动生效了,实际什么都没发生。
生日必须是真实日期
只校验格式不够:2023-02-30 格式合法但日期不存在,存进去之后年龄推导会得到负数或 NaN。
规则
| 规则 | 说明 |
|---|---|
| 不要求提权 | 更新档案不丢失任何数据 |
age 不可写 | 由 birthdate 推导,避免两者自相矛盾 |
| metadata 上限 | 只约束写入,不约束读取;否则历史数据会让 GET 校验失败 |