Skip to content

fix: instantiate SeaTableAPI directly with access-token instead of temp-api-token - #120

Open
AlexCXC wants to merge 3 commits into
masterfrom
fix/account-get-base
Open

AlexCXC wants to merge 3 commits into
masterfrom
fix/account-get-base

Conversation

@AlexCXC

@AlexCXC AlexCXC commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@seafile-dev seafile-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:请求修改。
审查 head:60ab602fad88733e1017964bdd52a7d07953bead。

新增问题:Account 创建的 Base 丢失资产接口仍需要的认证凭据;Socket.IO 服务端主动断开后刷新 JWT 仍走空 API-token 路径,不能重连。详见两条独立行内意见。

验证:实际导入精确 base/head SDK,通过真实 requests 访问本地 HTTP 接收器,后者执行当前 Web 上传链接/应用鉴权方法体,显式替代 ORM、RPC、签名及存储边界。base 上传链接成功;head 查询成功但上传链接及 upload_bytes_file 返回 403。真实 Socket.IO 回调的 base/head 对照复现主动断开刷新差异;connect/emit/sleep 在此探针中被替代,未宣称部署端重连测试。另以真实 python-socketio 本地 polling 验证初次连接和 join-room 均成功。Python 3.12 的原 dateutils 脚本及当前 head Actions 成功,但现有 CI 仅运行 dateutils,不能覆盖上述行为。

建议修复:迁移资产方法的认证协议,并保存可传递至 Socket.IO 克隆的 Account access-token 续期来源;将上传与主动断开重连场景加入 CI。

已重新读取设计文档:https://dev.seafile.com/seahub/smart-link/c48007d1-26a6-473e-85a2-a193799527d8/ 。直接获取 access-token 的主路径符合设计;设计应补充所有旧 API-token 消费方法及长连接续期的迁移契约,而非只替换初始化请求。本仓库问题独立于三个服务已有的签名/HTTP 鉴权混用问题。

Comment thread seatable_api/main.py
resp_json = response.json()
access_token = resp_json['access_token']
dtable_uuid = resp_json['dtable_uuid']
base = SeaTableAPI('', self.server_url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 保留资产接口可用的认证方式

影响:Account.get_base 返回的 Base 现在 token 为空,但 get_file_upload_link、get_file_download_link 等方法仍以 self.token 请求 app-* 接口。隔离 HTTP 对照中网关查询正常,上传链接及 upload_bytes_file 却发送空 Token 凭据并返回 403;旧版上传链接成功。

建议修复:将这些方法同步迁移到支持 access-token 或账号认证的资源接口,保留授权范围;不能直接把 access JWT 当 API token,也不应恢复对已弃用 temp-api-token 的依赖。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充当前设计及配套服务端的修复方向:Web b58180ff 的 _resolve_api_token 已接受 dtable access JWT,因此本评论中“不能直接把 access JWT 当 API token”的笼统限制不再适用。SDK 60ab602 的空凭据问题仍可复现,且同样影响 custom assets、第三方凭据和用户信息;应让这些方法使用已初始化的 access JWT headers,并保留普通 API-token Base 的兼容行为,不恢复 temp-api-token 依赖。服务端必须先上线该兼容支持。Socket.IO 的刷新来源丢失仍是另一条独立问题。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本轮复核 head 8291dca:本线程的空资源凭据问题已修复。8 处资源方法均改用 self.headers;真实回环 HTTP 对照中,附件上传/下载、自定义资产、第三方账号和用户信息均发送 access JWT 并成功,旧审查版本 60ab602 在同一接收器下仍失败。上层文件操作及普通永久/temp-token Base 的 JWT 刷新兼容也已验证。不再将本线程列为当前阻塞;独立的 Socket.IO 续期来源问题和 get_base 错误解析问题仍存在。此结论限于本地协议与精确源码隔离验证,非线上集成验收。

Comment thread seatable_api/main.py
access_token = resp_json['access_token']
dtable_uuid = resp_json['dtable_uuid']
base = SeaTableAPI('', self.server_url)
base._auth(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 为账号创建的 Base 保留续期能力

影响:这里仅初始化 access JWT,没有保留 Account 的刷新来源。SocketIO._on_io_disconnect 会无条件调用克隆 Base.auth(),后者仍拿空 self.token 请求 app-access-token;首次连接正常,但服务端主动断开后立即收到 403,无法重连,即使当前 JWT 尚未过期。

建议修复:保存 Account/workspace/Base 对应的 access-token 刷新提供者,让 auth() 和 Socket.IO 克隆通过它续期,并为普通 API-token Base 保留原行为;补充主动断开重连回归。

@seafile-dev seafile-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:请求修改。审查 head:60ab602fad88733e1017964bdd52a7d07953bead。

既有阻塞仍可复现:Account Base 的资产、第三方账号和用户信息等方法发送空凭据;Socket.IO 在服务端主动断开后以空 API token 刷新而无法重连。沿用原行内意见,不重复创建:
#120 (comment)
#120 (comment)
资产接口应使用已初始化的 access JWT headers,并保留普通 API-token Base 的兼容行为;配套 Web 已支持该认证方式。续期来源应保存并传递给 Socket.IO 克隆。

新增 Warning:get_base 绕过 parse_response,HTTP 错误失去原异常契约,详见本次行内意见。

验证:精确源码 base/head 对照及真实回环 HTTP 复现资产空凭据;真实本地 Socket.IO polling 首次连接成功,主动断开后 base 重新 join,head 刷新 403 且未重连。HTTP 401/403/404/429/500 JSON 错误在 head 变成 KeyError,502 HTML 变成 JSONDecodeError;仅恢复 parse_response 的隔离控制恢复原异常类型。原 dateutils 脚本退出 0。以上使用本地接收器,并替代 Web ORM/RPC/存储等边界,不是部署端 E2E 或完整服务集成。

已分析当前设计:https://dev.seafile.com/seahub/smart-link/e77b80c9-0f92-4ed9-b418-973412b0dd3b/ 。直接获取 access-token 符合主方向,但附件等后续调用及长连接续期迁移未完成;须先上线服务端兼容再迁移 SDK。建议设计补充 SDK 全部凭据消费者、续期和错误契约,并明确 scoped JWT 的资源边界。历史 c480 文档内容 API 当前返回 404。

Comment thread seatable_api/main.py
response = requests.get(self._get_base_access_token_url(workspace_id, base_name),
headers=self.token_headers,
timeout=self.timeout)
resp_json = response.json()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] 保留统一响应解析的异常契约

影响:access-token 接口返回 401/403、Base 不存在、限流或服务错误时,直接解析并索引字段会把原 ConnectionError 变成 KeyError('access_token'),HTML 网关错误则变成 JSONDecodeError。403 Token expired. 也不再抛出 AuthExpiredError,已有调用方的重新登录和错误处理分支因此无法正常接管;精确 base/head 的回环 HTTP 对照已复现。

建议修复:改用现有 parse_response(response),成功后再读取字段,并补充过期、无权限、不存在和非 JSON 错误响应的回归。

@seafile-dev seafile-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:仍请求修改;本次缩小问题集,替代此前关于资源空凭据的结论。
审查 head:8291dca9d51d3e59f6d7811bb93793b5c277cc6d。

已修复:附件、自定义资产、第三方账号和用户信息的 8 处请求现使用 access JWT headers;真实回环 HTTP 与旧审查版本对照通过,普通永久/temp-token Base 的资源调用及 JWT 轮换保持兼容。原线程已更新,不再作为阻塞:
#120 (comment)

剩余阻塞:Account 创建的 Base 及其克隆仍缺续期来源,真实 Socket.IO 首次连接成功,但服务端主动断开后以空 API token 刷新,403 且无法再次 join。建议保存 Account/workspace/Base 的续期提供者并传入克隆,保留普通 API-token Base 路径。沿用既有意见:
#120 (comment)

剩余警告:get_base 仍绕过 parse_response,HTTP JSON 错误变成 KeyError,HTML 错误变成 JSONDecodeError,过期响应不能触发 AuthExpiredError。建议恢复统一解析并补充错误响应回归。沿用既有意见:
#120 (comment)

验证:本轮重新取得精确 base、旧审查版本和当前 head,实际 requests 回环资源请求、失败响应矩阵、JWT 轮换与真实本地 Socket.IO polling 对照均完成;旧续期及错误解析缺陷仍可复现。原 dateutils 脚本通过。Web 接收器的验签、ORM/RPC/存储等边界被替代,不是部署端 E2E、真实存储或完整服务验证。当前 head build job 131830202421 成功;日志仅运行 tests/dateutils_test.py,不覆盖此次认证迁移,combined status 仍为 pending,不等同全部保护规则通过。

已分析当前设计:https://dev.seafile.com/seahub/smart-link/e77b80c9-0f92-4ed9-b418-973412b0dd3b/ 。直接获取 access-token 和后续资源认证已符合主方向,但续期及错误契约仍需完成。建议设计补充刷新来源、克隆生命周期和 scoped JWT 的资源边界;Web 的受限 token 范围问题仍由原线程覆盖。必须先上线服务端兼容再迁移 SDK;仍使用 Python runner 时保留四服务一致的显式 token,不应仅因 SDK 迁移就删配置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants