jackwener/OpenCLI · error · AuthRequiredError

${result.detail}

Error message

${result.detail}

What it means

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.

Source

Thrown at clis/weibo/auth.js:47

    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`;
}

async function verifyWeiboIdentity(page) {
  if (!await hasWeiboSessionCookie(page)) {
    throw new AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing');
  }
  await page.goto('https://weibo.com/');
  await page.wait(3);
  // getSelfUid throws AuthRequiredError when no logged-in uid can be resolved.
  const uid = await getSelfUid(page);
  if (typeof uid !== 'string' || !uid.trim()) {
    throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');
  }
  const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
  if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /ajax/profile/info`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Weibo whoami failed: ${result.detail}`);
  if (!result || Array.isArray(result) || typeof result !== 'object') {
    throw new CommandExecutionError('Weibo whoami returned malformed probe payload');
  }
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Weibo probe: ${JSON.stringify(result)}`);
  if (!result.user_id) throw new CommandExecutionError('Weibo whoami returned no user id');
  return { user_id: result.user_id, screen_name: result.screen_name, profile_url: result.profile_url };
}

registerSiteAuthCommands({
  site: 'weibo',
  domain: 'weibo.com',
  loginUrl: 'https://weibo.com/login',
  columns: ['user_id', 'screen_name', 'profile_url'],
  quickCheck: hasWeiboSessionCookie,
  verify: verifyWeiboIdentity,
  poll: async (page) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to weibo.com to refresh SUB/SUBP cookies, then retry
  2. Read result.detail for the specific auth reason reported by the probe
  3. Ensure the probe request sends required anti-CSRF headers (e.g. X-XSRF-TOKEN)
  4. Try from a different network/IP if Weibo risk control is challenging the session

Example fix

// before
const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);
// after
let result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
if (result?.kind === 'auth') {
  await runWeiboLogin(page); // refresh session cookies
  result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
}
if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check the probe endpoint reaches an authenticated response
const probe = await page.evaluate(() => fetch('/ajax/profile/info', { credentials: 'include' }).then(r => r.status));
if (probe === 401 || probe === 403) throw new Error('Weibo session rejected — re-login required');

Try / catch

try {
  await verifyWeiboIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    console.error(`Weibo auth rejected: ${e.message} — refresh session cookies and retry.`);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b9b0bf31cd934425. Report an issue: GitHub.