{"record":{"id":"b9b0bf31cd934425","repo":"jackwener/OpenCLI","slug":"result-detail-b9b0bf","errorCode":null,"errorMessage":"${result.detail}","messagePattern":"\\$\\{result\\.detail\\}","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/weibo/auth.js","lineNumber":47,"sourceCode":"    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`;\n}\n\nasync function verifyWeiboIdentity(page) {\n  if (!await hasWeiboSessionCookie(page)) {\n    throw new AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing');\n  }\n  await page.goto('https://weibo.com/');\n  await page.wait(3);\n  // getSelfUid throws AuthRequiredError when no logged-in uid can be resolved.\n  const uid = await getSelfUid(page);\n  if (typeof uid !== 'string' || !uid.trim()) {\n    throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');\n  }\n  const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\n  if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /ajax/profile/info`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Weibo whoami failed: ${result.detail}`);\n  if (!result || Array.isArray(result) || typeof result !== 'object') {\n    throw new CommandExecutionError('Weibo whoami returned malformed probe payload');\n  }\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Weibo probe: ${JSON.stringify(result)}`);\n  if (!result.user_id) throw new CommandExecutionError('Weibo whoami returned no user id');\n  return { user_id: result.user_id, screen_name: result.screen_name, profile_url: result.profile_url };\n}\n\nregisterSiteAuthCommands({\n  site: 'weibo',\n  domain: 'weibo.com',\n  loginUrl: 'https://weibo.com/login',\n  columns: ['user_id', 'screen_name', 'profile_url'],\n  quickCheck: hasWeiboSessionCookie,\n  verify: verifyWeiboIdentity,\n  poll: async (page) => {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/auth.js#L29-L65","documentation":"After resolving the uid, verifyWeiboIdentity runs an in-page identity probe (/ajax/profile/info). If the probe reports kind 'auth', the code rethrows AuthRequiredError('weibo.com', result.detail) — the session failed authorization while fetching the user's own profile.","triggerScenarios":"The probe's fetch of /ajax/profile/info returned an auth-failure payload (401/403-like or redirect-to-login response), propagated as result.kind === 'auth' with a detail message.","commonSituations":"Cookies present but expired mid-request; Weibo requires re-verification (risk control) on the account; request missing required CSRF/xsrf token after page update; IP flagged requiring login.","solutions":["Re-login to weibo.com to refresh SUB/SUBP cookies, then retry","Read result.detail for the specific auth reason reported by the probe","Ensure the probe request sends required anti-CSRF headers (e.g. X-XSRF-TOKEN)","Try from a different network/IP if Weibo risk control is challenging the session"],"exampleFix":"// before\nconst result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\nif (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);\n// after\nlet result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\nif (result?.kind === 'auth') {\n  await runWeiboLogin(page); // refresh session cookies\n  result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\n}\nif (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);","handlingStrategy":"try-catch","validationCode":"// pre-check the probe endpoint reaches an authenticated response\nconst probe = await page.evaluate(() => fetch('/ajax/profile/info', { credentials: 'include' }).then(r => r.status));\nif (probe === 401 || probe === 403) throw new Error('Weibo session rejected — re-login required');","typeGuard":null,"tryCatchPattern":"try {\n  await verifyWeiboIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error(`Weibo auth rejected: ${e.message} — refresh session cookies and retry.`);\n  } else throw e;\n}","preventionTips":["Refresh SUB/SUBP cookies regularly; expired-but-present cookies trigger this","Send required anti-CSRF headers with profile API calls","Watch for Weibo risk-control challenges on the account","Test the session with a lightweight authenticated request before publishing"],"tags":["auth","weibo","api"],"backgroundTag":"weibo-auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}