Repository navigation
签发 API 令牌结果未知时锁住「签发」,只给「核对」 - #225
Merged
lc-cn merged 2 commits intoDec 1, 2026
Merged
Conversation
管理员「为用户签发」和个人设置「新建令牌」遇到结果未知(504 instance_timeout + requestOutcome unknown、断网、代理返回的裸 502/504)时,原来只显示错误, 「签发」「创建」仍可点,再点会多签一个令牌,而第一个令牌的明文已经拿不到。 - 新增 token-create-outcome.mjs:判断结果是否未知;「核对」按名称、用户和 创建时间在令牌列表里找刚才的令牌,找到就提示吊销后重签;没找到且距发出 不足 30 秒时只说「暂未找到」,不解锁;回复里没有令牌列表时不下结论。 - 锁定状态保存在页面上(个人设置弹窗常驻),关掉弹窗再打开仍锁住。 - IamRequestError 和 /auth 失败结果保留 Host 给的 requestOutcome。 - 个人设置弹窗请求进行中不能关闭。 关联 #64 token-create-unknown-outcome Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SLUGBDtJbRzDTQgkyE1mGh
Deploying zhin-demo-console with
|
| Latest commit: |
de9f278
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7dd4993a.console-axj.pages.dev |
| Branch Preview URL: | https://console-token-create-unknown.console-axj.pages.dev |
There was a problem hiding this comment.
🟡 Changes recommended
Critical gaps in issuance locking—stale reconciliation results, clock-skew-sensitive checks, and unreadable success responses—can allow repeat token creation while a previous issuance remains unresolved.
3 open issues
What changed in this PR
本 PR 针对 #64 的令牌签发结果未知问题,在管理员和个人设置页面阻止直接重试,改为先读取令牌列表核对,降低重复签发且丢失密钥的风险。
Changes:
- 两个签发弹窗新增未知结果锁定和只读核对流程,关闭后保留锁定状态。
- 保留 Host 的
requestOutcome,识别网络故障及裸 502/504,并增加核对等待窗口。 - 补充英文提示和回归测试,复用现有状态组件,不修改样式。
| File | Description |
|---|---|
tests/token-create-unknown-outcome.test.mjs |
覆盖结果判断、核对流程及弹窗约束。 |
console-ui/src/utils/console-auth-model.mjs |
保留认证失败回复的 requestOutcome。 |
console-ui/src/utils/console-auth-model.d.mts |
扩展认证失败类型。 |
console-ui/src/utils/console-auth-api.ts |
提供原始个人令牌列表读取接口。 |
console-ui/src/pages/account/index.tsx |
为个人令牌创建添加锁定、核对及关闭保护。 |
console-ui/src/pages/access/tokens.tsx |
为管理员签发添加页面级锁定和核对流程。 |
console-ui/src/pages/access/token-create-outcome.mjs |
集中实现未知结果识别和令牌列表核对。 |
console-ui/src/pages/access/token-create-outcome.d.mts |
定义核对计划与结果类型。 |
console-ui/src/pages/access/iam-request.mjs |
在 IAM 错误中传递请求结果信息。 |
console-ui/src/pages/access/iam-request.d.mts |
扩展 IAM 错误声明。 |
console-ui/src/i18n/messages.en.admin.mjs |
添加锁定和核对流程的英文提示。 |
Review effort: Balanced
- 「核对」改为对照签发前页面已列出的令牌 id:不在其中的同名令牌才算刚签出 的那个;页面没有该用户的列表时,任何同名令牌都算(不再用 createdAt 和浏览器时间比较,避免时钟偏差把新令牌当成旧的而解锁)。 - 核对结果只作用于它开始时的锁定状态,过期的核对不会清掉更新的锁定。 - 2xx 但没有令牌(回复丢失或读不出)也按结果未知处理,锁住「签发」「创建」。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SLUGBDtJbRzDTQgkyE1mGh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

关联 #64 的
token-create-unknown-outcome。问题
签发 API 令牌时,如果遇到「结果未知」,弹窗只显示「实例不可用……建议 5 秒后重试」,「签发」按钮仍然可以点。再点一次就会再签一个令牌。令牌只显示一次,如果第一次其实已经签出,用户拿不到它,却多了一个有效令牌。
确认问题存在的依据(在 feat 上核实):
pages/access/tokens.tsx里IssueTokenDialog的TOKENS_CREATE失败后只调用setError(caught),没有判断结果是否未知。pages/account/index.tsx里CreateTokenDialog(createOwnToken)失败后同样只显示错误。iam.tokens.create,返回 504instance_timeout+requestOutcome: 'unknown'。修复前「签发」仍可点,可以发出第二次请求。改法
pages/access/token-create-outcome.mjs(附.d.mts):tokenCreateUnknown:判断签发结果是否未知。以下情况都算未知:outcomeUnknown、断网、代理返回不带 Host 包体的裸 502/504。tokenCreateCheck:「核对」逻辑,按名称、用户和创建时间在令牌列表里找刚才的令牌。tokenListOf:读取令牌列表回复。IamRequestError和/auth/*的失败结果现在保留 Host 返回的requestOutcome。这样instance_unavailable被 Host 标为unknown时,也会按结果未知处理。验证
npx tsc --noEmit、pnpm test(1979 项通过)、pnpm lint:css、pnpm build(首屏 507.5 KB gzip,预算 540 KB)全部通过。tests/token-create-unknown-outcome.test.mjs:修复前失败,修复后通过。覆盖结果未知的判断、requestOutcome的传递、裸 502/504、「核对」的各种结果(找到、早于 30 秒、超过 30 秒、旧的同名令牌、读不到列表)、英文文案,以及两个弹窗的源码约束。iam.tokens.create返回 504 unknown,在浅色/深色、375/1280 宽度下检查:「签发」被禁用,强制再点也只发出 1 次创建请求;「核对」后显示「已有名为…的令牌,请吊销后重签」;没有横向滚动。独立审查
另起的只读审查 agent 提出 7 条,全部核实属实并已修复:
tokenListOf,个人设置用新增的readOwnTokenList。没有列表就不下结论。action: 'create'显示「创建」的文案。checking挡住。界面规范(#111)
StatusState kind="unknown"(技术详情折叠,只在异常时出现)和对话框按钮,没有新写样式或任意值。本次没有改动样式。
Generated by Claude Code