Skip to content

Commit bb6c80a

Browse files
author
zxcv1234
committed
fix(oauth): require step9 submit for local cpa and stop step8 debugger cleanly
1 parent 79a6f13 commit bb6c80a

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ Step 3 使用的注册邮箱。
304304

305305
- 自动填写 localhost 回调地址
306306
- 自动点击“提交回调 URL”
307+
- 即使 CPA 面板本身部署在 `localhost` / `127.0.0.1`,也不会跳过这一步
307308
- 必须等到 CPA 面板出现精确的 `认证成功!` 状态徽标后,才判定成功
308309
- 成功后会自动关闭匹配 `http://localhost:1455/auth` 这一类前缀的 localhost 残留页面
309310

‎background.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ function isLocalCpaUrl(rawUrl) {
249249
}
250250

251251
function shouldBypassStep9ForLocalCpa(state) {
252-
return Boolean(state?.localhostUrl) && isLocalCpaUrl(state?.vpsUrl);
252+
// 即使 CPA 面板本身部署在 localhost,也必须显式执行步骤 9:
253+
// 回填 callback URL、点击提交,并等待面板出现“认证成功!”。
254+
// 否则会出现步骤 8 捕获到 localhost 后流程直接结束的问题。
255+
return false;
253256
}
254257

255258
function matchesSourceUrlFamily(source, candidateUrl, referenceUrl) {
@@ -1179,6 +1182,8 @@ async function humanStepDelay(min = HUMAN_STEP_DELAY_MIN, max = HUMAN_STEP_DELAY
11791182
}
11801183

11811184
async function clickWithDebugger(tabId, rect) {
1185+
throwIfStopped();
1186+
11821187
if (!tabId) {
11831188
throw new Error('未找到用于调试点击的认证页面标签页。');
11841189
}
@@ -1197,10 +1202,14 @@ async function clickWithDebugger(tabId, rect) {
11971202
}
11981203

11991204
try {
1205+
throwIfStopped();
1206+
12001207
const x = Math.round(rect.centerX);
12011208
const y = Math.round(rect.centerY);
12021209

12031210
await chrome.debugger.sendCommand(target, 'Page.bringToFront');
1211+
throwIfStopped();
1212+
12041213
await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
12051214
type: 'mouseMoved',
12061215
x,
@@ -1209,6 +1218,8 @@ async function clickWithDebugger(tabId, rect) {
12091218
buttons: 0,
12101219
clickCount: 0,
12111220
});
1221+
throwIfStopped();
1222+
12121223
await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
12131224
type: 'mousePressed',
12141225
x,
@@ -1217,6 +1228,8 @@ async function clickWithDebugger(tabId, rect) {
12171228
buttons: 1,
12181229
clickCount: 1,
12191230
});
1231+
throwIfStopped();
1232+
12201233
await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
12211234
type: 'mouseReleased',
12221235
x,

‎tests/step9-cpa-mode.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ assert.strictEqual(api.isLocalCpaUrl('notaurl'), false, '非法 URL 不应视为
4343
assert.strictEqual(api.shouldBypassStep9ForLocalCpa({
4444
vpsUrl: 'http://127.0.0.1:8317/management.html#/oauth',
4545
localhostUrl: 'http://127.0.0.1:8317/codex/callback?code=abc&state=xyz',
46-
}), true, '本地 CPA 且已有 callback 时应跳过远程提交流程');
46+
}), false, '即使 CPA 在本地,也不应跳过步骤 9 的回填提交流程');
4747

4848
assert.strictEqual(api.shouldBypassStep9ForLocalCpa({
4949
vpsUrl: 'https://example.com/management.html#/oauth',

0 commit comments

Comments
 (0)