接口参考登录与会话
切换当前租户
POST /api/auth/v1/switch-tenant,switchTenant 的请求参数和响应结构。
POST /api/auth/v1/switch-tenant
| 项目 | 内容 |
|---|---|
| 操作标识 | switchTenant |
| 认证 | 登录会话 Cookie |
PostgreSQL 持久化;角色、租户状态与成员资格在每次请求的数据库事务中重新校验。未配置 DATABASE_URL 时返回 503。
会话写请求需要合法的 Origin 和与当前 Cookie 绑定的 X-CSRF-Token。登录成功后应重新获取 CSRF 令牌。具体权限由目标资源归属和当前授权决定,见认证约定。
请求参数
| 名称 | 位置 | 必填 | 类型 | 说明与约束 |
|---|---|---|---|---|
| X-CSRF-Token | header | 是 | string | 先 GET /api/auth/v1/csrf 获取,与当前 Cookie 会话绑定;写请求同时要求 Origin 等于配置的 PUBLIC_ORIGIN。;最短 1 |
请求体
请求体必填。
内容类型:application/json。
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
| tenant_id | string | 是 | 租户 UUID;null 表示查看全部已授权租户,不扩大访问权限。单租户成员自动进入所属租户。;格式:uuid;可为 null |
完整请求结构(含引用定义)
{
"$ref": "#/$defs/IAMSwitchTenant",
"$defs": {
"IAMSwitchTenant": {
"type": "object",
"additionalProperties": false,
"properties": {
"tenant_id": {
"type": "string",
"format": "uuid",
"description": "租户 UUID;null 表示查看全部已授权租户,不扩大访问权限。单租户成员自动进入所属租户。",
"nullable": true
}
},
"required": [
"tenant_id"
]
}
}
}响应
| HTTP 状态 | 含义 |
|---|---|
| 200 | 成功 |
| 400 | 参数错误 |
| 401 | 登录无效或已撤销 |
| 403 | 权限、范围或 CSRF 校验失败 |
| 404 | 记录不存在 |
| 409 | 引用或唯一性冲突 |
| 429 | 请求过于频繁 |
| 503 | 数据库未配置或不可用 |
200 · application/json 响应结构
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
| data | UserIdentity | 是 | — |
| request_id | string | 是 | — |
{
"$ref": "#/$defs/UserIdentityResponse",
"$defs": {
"UserIdentityResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"data": {
"$ref": "#/$defs/UserIdentity"
},
"request_id": {
"type": "string"
}
},
"required": [
"data",
"request_id"
]
},
"UserIdentity": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"display_name": {
"type": "string"
},
"platform_permissions": {
"type": "array",
"items": {
"type": "string"
}
},
"tenants": {
"type": "array",
"items": {
"$ref": "#/$defs/TenantMembership"
}
},
"active_tenant_id": {
"type": "string",
"nullable": true
}
},
"required": [
"id",
"display_name",
"platform_permissions",
"tenants",
"active_tenant_id"
]
},
"TenantMembership": {
"type": "object",
"additionalProperties": false,
"properties": {
"tenant_id": {
"type": "string"
},
"name": {
"type": "string"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
},
"permissions": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"tenant_id",
"name",
"roles",
"permissions"
]
}
}
}400 / 401 / 403 / 404 / 409 / 429 / 503 · application/json 响应结构
{
"$ref": "#/$defs/ErrorResponse",
"$defs": {
"ErrorResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"error": {
"$ref": "#/$defs/ErrorDetail"
},
"request_id": {
"type": "string"
}
},
"required": [
"error",
"request_id"
]
},
"ErrorDetail": {
"type": "object",
"additionalProperties": false,
"properties": {
"code": {
"type": "string",
"enum": [
"NOT_IMPLEMENTED",
"NOT_FOUND",
"AUTH_REQUIRED",
"FORBIDDEN",
"VALIDATION_FAILED",
"CONFLICT",
"SERVICE_UNAVAILABLE",
"INTERNAL_ERROR",
"RATE_LIMITED"
]
},
"message": {
"type": "string"
},
"retryable": {
"type": "boolean"
},
"fields": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"required": [
"code",
"message",
"retryable"
]
}
}
}响应中的 request_id 用于排查请求;异步操作以任务最终状态为准。参阅调用约定、异步任务和错误处理。
本页由版本化 OpenAPI 契约生成。通用资源响应允许的任意字段以运行服务为准,不据此推断尚未定义的字段。
