Skip to content

fix: restore missing tab cleanup functions, fix test mocks, improve Hotmail AADSTS90023 error handling#31

Merged
QLHazyCoder merged 2 commits into
masterfrom
copilot/fix-hotmail-validation-error
Apr 13, 2026
Merged

fix: restore missing tab cleanup functions, fix test mocks, improve Hotmail AADSTS90023 error handling#31
QLHazyCoder merged 2 commits into
masterfrom
copilot/fix-hotmail-validation-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Hotmail account validation consistently fails with AADSTS90023 because Chrome extension service workers include an Origin: chrome-extension://... header that Microsoft's token endpoint rejects unless the origin is registered as an allowed SPA/Native origin in Azure AD.

Changes

background.js — Restore missing functions

buildLocalhostCleanupPrefix and closeTabsByUrlPrefix were called in handleStepData (step 9) but never defined, causing a runtime ReferenceError. Restored from an earlier PR:

function buildLocalhostCleanupPrefix(rawUrl) {
  if (!isLocalhostOAuthCallbackUrl(rawUrl)) return '';
  const parsed = parseUrlSafely(rawUrl);
  return parsed ? `${parsed.origin}/auth` : '';
}

background.js — Hotmail token refresh: redirect_uri + better error message

  • Adds redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient to the refresh-token request — the standard native-client redirect URI for public clients, which satisfies the requirement for apps registered as "Mobile and desktop applications"
  • Detects AADSTS90023 in the error response and replaces the cryptic Microsoft trace with a clear, actionable message explaining the required Azure AD app registration change

Test fixes

  • step8-stop-cleanup.test.js: added getState and isAutoRunScheduledState mocks; requestStop calls getState() which was absent from the evaluation context
  • step9-localhost-cleanup-scope.test.js: added the two restored functions to the extracted bundle so handleStepData can resolve them at evaluation time

…st mocks, improve Hotmail AADSTS90023 error

Agent-Logs-Url: https://github.com/QLHazyCoder/codex-oauth-automation-extension/sessions/2111e544-f823-4faa-b8b6-57f506fe45ac

Co-authored-by: QLHazyCoder <109800873+QLHazyCoder@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Hotmail validation error fix: restore missing tab cleanup functions, fix test mocks, improve Hotmail AADSTS90023 error handling Apr 12, 2026
Copilot AI requested a review from QLHazyCoder April 12, 2026 19:36
@QLHazyCoder
Copy link
Copy Markdown
Owner

QLHazyCoder commented Apr 13, 2026

codex-gpt-5.4分析结果(不一定完全正确,请仔细确认无问题下面继续评论):

  1. background.js:1271-1274
    buildLocalhostCleanupPrefix 并没有按历史实现恢复,而是固定返回 ${parsed.origin}/auth。当前仓库 isLocalhostOAuthCallbackUrl 明确支持 /auth/callback/codex/callback 两种路径,因此 handleStepData(9) 在处理 http://127.0.0.1:8317/codex/callback?... 时会把前缀算成 http://127.0.0.1:8317/authcloseTabsByUrlPrefix 无法继续清掉同源的 /codex/... 残留页。现有 step9-localhost-cleanup-scope.test.js 只校验了精确 callback 页关闭,没有覆盖这个回归。

  2. background.js:772, 808
    Hotmail 刷新请求现在对所有账号都强制附带 redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient,但仓库当前是让用户手动导入任意 clientId + refreshToken,并没有限制这些 token 必须来自 nativeclient。微软官方的 refresh token 请求示例也没有要求携带 redirect_uri,反而只在授权码兑换时要求它与最初授权时一致。这里把 redirect URI 写死,存在把原本可刷新的 token 变成 invalid_grant/invalid_request 的风险;同时新的错误提示把 “SPA” 与 nativeclient 放在一起指导,也会把 Azure AD 配置方向引错。

@QLHazyCoder QLHazyCoder merged commit 65d43a0 into master Apr 13, 2026
@QLHazyCoder
Copy link
Copy Markdown
Owner

QLHazyCoder commented Apr 13, 2026

感谢贡献这次改动,Step 9 清理函数恢复、Step 8/9 回归测试补齐以及 Hotmail 校验报错优化的主体内容已经吸收到目标分支了。我这边另外补了一个 localhost 清理前缀兼容 /codex/callback 的修正,后续如果你还有类似改进可以继续提交。

@QLHazyCoder QLHazyCoder deleted the copilot/fix-hotmail-validation-error branch April 13, 2026 08:37
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