Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions web/strategy-switch-console/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3823,8 +3823,29 @@ async function finishLogin(request, env) {
if (tokenStage.timedOut) return loginTimeoutResponse("token_exchange");
const tokenResponse = tokenStage.value;
const tokenPayload = await tokenResponse.json();
if (!tokenResponse.ok || !tokenPayload.access_token) {
return html(renderMessage("登录失败", "GitHub token exchange 失败。"), 502, clearOAuthCookie());
const tokenPayloadIsObject = tokenPayload !== null && typeof tokenPayload === "object";
if (!tokenResponse.ok || !tokenPayloadIsObject || !tokenPayload.access_token) {
const status = Number.isSafeInteger(tokenResponse?.status) ? tokenResponse.status : null;
const allowedOauthErrors = new Set([
"incorrect_client_credentials",
"redirect_uri_mismatch",
"bad_verification_code",
"unverified_user_email",
]);
const errorCategory = tokenPayloadIsObject && typeof tokenPayload.error === "string"
&& allowedOauthErrors.has(tokenPayload.error)
? tokenPayload.error
: "unknown";
console.warn("github_token_exchange_failed", {
http_status: status,
error_category: errorCategory,
});
const statusLabel = status === null ? "不可用" : String(status);
return html(
renderMessage("登录失败", `GitHub 凭证交换未成功(HTTP ${statusLabel},类别:${errorCategory})。请从登录入口重新开始。`),
502,
clearOAuthCookie(),
);
}

const userStage = await runLoginGithubStage("user_lookup", () => fetchWithTimeout("https://api.github.com/user", {
Expand Down
Loading