From 6bae0bab5ebf2f9bf1a14a5b1d74a7e5662baf2e Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 26 Nov 2026 20:34:03 +0800 Subject: [PATCH] =?UTF-8?q?15m44z=20=E7=BB=AD=EF=BC=8819:59=20=E6=A0=B9?= =?UTF-8?q?=E6=B2=BB=EF=BC=89=EF=BC=9AOAuth=20=E5=9B=9E=E8=B0=83=E5=86=99?= =?UTF-8?q?=20fresh=20flag=EF=BC=8Cgh=5Fcfg=20=E8=AF=BB=E5=88=B0=E5=85=8D?= =?UTF-8?q?=E9=AA=8C=E6=B4=BB=20gh=5Foauth.php=EF=BC=9AOAuth=20=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E5=AD=98=20token=20=E5=90=8E=E5=86=99=20gh=5Foauth=5F?= =?UTF-8?q?fresh/{md5(player)}.json=EF=BC=8810min=20=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=EF=BC=89=EF=BC=9B=20gh=5Fcfg.php=EF=BC=9A=E8=AF=BB=E5=88=B0=20?= =?UTF-8?q?fresh=20flag=20=E2=86=92=20=E5=85=8D=20/user=20=E9=AA=8C?= =?UTF-8?q?=E6=B4=BB=E7=9B=B4=E6=8E=A5=E5=88=A4=E6=9C=89=E6=95=88=EF=BC=88?= =?UTF-8?q?gh=5Ftoken=5Ffresh=3Dtrue=EF=BC=89=EF=BC=8C=20=E6=A0=B9?= =?UTF-8?q?=E6=B2=BB=20CF=20=E8=BE=B9=E7=BC=98=20/user=20=E9=AA=8C?= =?UTF-8?q?=E6=B4=BB=E5=81=B6=E5=8F=91=20401=20=E6=8A=8A=E5=88=9A=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=9A=84=E6=9C=89=E6=95=88=20token=20=E8=AF=AF?= =?UTF-8?q?=E5=88=A4=E6=88=90=E3=80=8Ctoken=20=E5=8F=AF=E8=83=BD=E5=B7=B2?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E3=80=8D=E3=80=82=20player.php=20=E6=8C=89?= =?UTF-8?q?=20gh=5Ftoken=5Ffresh=20=E5=8C=BA=E5=88=86=E6=96=87=E6=A1=88?= =?UTF-8?q?=EF=BC=9A=E5=88=9A=E6=8E=88=E6=9D=83=E2=86=92=E5=B7=B2=E6=8E=88?= =?UTF-8?q?=E6=9D=83=EF=BC=8C=E8=80=81=20token=E2=86=92=E5=B7=B2=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/gh_cfg.php | 15 +++++++++++++++ api/gh_oauth.php | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/api/gh_cfg.php b/api/gh_cfg.php index 4483fee..237b41d 100644 --- a/api/gh_cfg.php +++ b/api/gh_cfg.php @@ -69,6 +69,20 @@ if ($cfg['gh_enabled'] && $probeTk !== '') { $st->bindValue(':p', $probePlayer, SQLITE3_TEXT); $trow = $st->execute()->fetchArray(SQLITE3_ASSOC); if ($trow && !empty($trow['access_token'])) { + // ★ 15m44z 续(19:59 根治):OAuth 回调 fresh flag(10min,按玩家名)→ 免验活必有效。 + // 彻底避开 CF 边缘 /user 验活偶发 401 把刚授权的有效 token 误判成「可能已失效」。 + $freshDir = dirname(__DIR__) . '/../gh_oauth_fresh'; + $freshFlag = $freshDir . '/' . md5($probePlayer) . '.json'; + if (is_readable($freshFlag)) { + if (is_array($ff) && (int)$ff['exp'] > time() && (string)($ff['player'] ?? '') === $probePlayer) { + $ghAuthorized = true; + $ghTokenFresh = true; + ghLog('cfg verify player=' . $probePlayer . ' fresh-flag=y (OAuth 回调刚授权, 免验活)'); + } else { + @unlink($freshFlag); // 过期/玩家不匹配 → 清掉 + } + } + if (!$ghTokenFresh) { // ★ 15m44z 续(19:59 修):刚授权(updated_at 距今 < 5min)→ token 必有效,免验活。 // 根治「刚走完 gh_oauth 回调回来,gh_cfg 却显示 token 可能已失效」的误导。 // 老 token(>5min)才走 /user 验活判真失效。 @@ -86,6 +100,7 @@ if ($cfg['gh_enabled'] && $probeTk !== '') { ghLog('cfg verify player=' . $probePlayer . ' token=' . substr((string)$trow['access_token'], 0, 8) . ' status=' . (int)($v['status'] ?? -1) . ' ok=' . ($v['ok'] ? 'y' : 'n')); } + } // end if (!ghTokenFresh) } else { ghLog('cfg verify player=' . $probePlayer . ' no token row in gh_auth_tokens'); } diff --git a/api/gh_oauth.php b/api/gh_oauth.php index a861974..1a3b05f 100644 --- a/api/gh_oauth.php +++ b/api/gh_oauth.php @@ -202,6 +202,16 @@ if ($code !== '') { } catch (\Throwable $e3) { /* 忽略,回跳仍成功 */ } } + // ★ 15m44z 续(19:59 根治):OAuth 回调成功后写 fresh flag(短期 10min,按玩家名) + // gh_cfg 读到 flag → 免 /user 验活直接判有效,彻底避开 CF 边缘偶发 401 把刚授权的有效 + // token 误判成「token 可能已失效」。flag 路径 __DIR__/../gh_oauth_fresh/{player}.json + $freshDir = dirname(__DIR__) . '/../gh_oauth_fresh'; + @mkdir($freshDir, 0755, true); + @file_put_contents($freshDir . '/' . md5($player) . '.json', json_encode([ + 'player' => $player, 'ts' => time(), 'exp' => time() + 600, + ])); + @chmod($freshDir . '/' . md5($player) . '.json', 0600); + // 回跳前端工单页,带成功标记 header('Location: ' . $baseSite . '/player.php?gh_ok=1&gh_user=' . urlencode($ghUser)); exit;