jackwener/OpenCLI · error · AuthRequiredError

${probe.detail}

Error message

${probe.detail}

What it means

After confirming the sessionid cookie, the tool navigates to the platform and runs an in-page probe. When the probe reports kind:'auth' (redirect to login.html, or auth_data returning base_resp.ret != 0, or empty finder_user), the detail is rethrown as an AuthRequiredError — the cookie exists but the server considers the session invalid.

Source

Thrown at clis/wechat-channels/auth.js:42

        body: '{}',
      });
      if (!r.ok) return { kind: 'http', httpStatus: r.status };
      const d = await r.json();
      if (!d || d.base_resp?.ret !== 0) {
        return { kind: 'auth', detail: 'WeChat Channels auth_data base_resp.ret=' + String(d?.base_resp?.ret) };
      }
      const fu = d.data?.finder_user || d.finder_user || {};
      const userId = String(fu.uniq_id || fu.username || '');
      const name = String(fu.nickname || fu.name || '');
      if (!userId && !name) {
        return { kind: 'auth', detail: 'WeChat Channels auth_data 200 but finder_user empty' };
      }
      return { ok: true, user_id: userId, name };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (probe?.kind === 'auth') throw new AuthRequiredError('channels.weixin.qq.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from auth_data`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`WeChat Channels whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected WeChat Channels probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, name: probe.name };
}

registerSiteAuthCommands({
  site: 'wechat-channels',
  domain: 'channels.weixin.qq.com',
  loginUrl: 'https://channels.weixin.qq.com/login.html?from=assistant',
  columns: ['user_id', 'name'],
  quickCheck: hasWechatChannelsSessionCookie,
  verify: verifyWechatChannelsIdentity,
  poll: async (page) => {
    if (!await hasWechatChannelsSessionCookie(page)) {
      throw new AuthRequiredError('channels.weixin.qq.com', 'Waiting for WeChat Channels sessionid cookie');
    }
    return verifyWechatChannelsIdentity(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the login flow (login.html QR scan) to obtain a fresh session, then retry.
  2. Check the detail string: base_resp.ret codes indicate server-side rejection — search the code or re-login.
  3. Confirm the logged-in account actually has a Channels/视频号 identity.
  4. Avoid rapid automated calls that may trigger risk-control; add delays between operations.
  5. If a redirect to login.html persists despite fresh cookies, clear site cookies and log in again.

Example fix

// before
wechat-channels whoami   # sessionid exists but stale
// after
wechat-channels login    # refresh session via QR
wechat-channels whoami
Defensive patterns

Strategy: retry

Validate before calling

// After goto, confirm we weren't bounced to login before probing
await page.goto('https://channels.weixin.qq.com/platform');
if (/login\.html/.test(await page.evaluate('location.href'))) {
  await runLoginFlow(); // re-auth before calling verify
}

Type guard

function isAuthProbe(p) { return p != null && (p.ok === true || p.kind === 'auth' || p.kind === 'http' || p.kind === 'exception'); }

Try / catch

try {
  const identity = await verifyWechatChannelsIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await runLoginFlow();      // refresh session via QR
    identity = await verifyWechatChannelsIdentity(page);
  } else throw e;
}

Prevention

When it happens

Trigger: Cookie present but expired/revoked server-side (platform redirects to login.html); auth_data endpoint replies with non-zero base_resp.ret (e.g. ret 200013-type invalid-session codes); account lacks finder_user data so identity extraction fails.

Common situations: WeChat invalidated the session after password change or security check; session cookie present but CSRF/refresh tokens gone; logging in with an account that has no Channels (视频号) identity; risk-control flagging automated access.

Related errors


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