Skip to content

feat(auth): add login/whoami for nowcoder, jike, maimai, jimeng#1878

Open
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:feat/auth-todo-sites
Open

feat(auth): add login/whoami for nowcoder, jike, maimai, jimeng#1878
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:feat/auth-todo-sites

Conversation

@Benjamin-eecs
Copy link
Copy Markdown
Contributor

Description

Implements the four single-site login/whoami TODOs from the tracking issue, built on the registerSiteAuthCommands framework and matching the merged weibo / gitee / deepseek / hupu adapters. Each site was verified end to end against a real logged-in browser session; the sample output below uses placeholder values.

Per-site approach:

  • nowcoder: gate on the t session cookie via CDP getCookies; the numeric uid is read from the first nav profile link (the SSR avatar link, ahead of feed recommendations) and identity is confirmed through the gateway profile API at gw-c.nowcoder.com.
  • jike: the web app stores a JWT under localStorage JK_ACCESS_TOKEN and forwards it as the x-jike-access-token header to api.ruguoapp.com /1.0/users/profile. The JWT payload is encrypted, so the API is the identity source (deepseek-style token probe).
  • maimai: the logged-in member is server-rendered into an inline userObj = JSON.parse('{...}') script (declared with let, so it never lands on window, and the userCardStr global is corrupted to "[object Object]"). The probe parses that JSON, whose presence is the login signal.
  • jimeng: the jianying passport endpoint /passport/account/info/v2/ returns the account for the session; an anonymous visitor comes back with is_visitor_account true, which is the login gate. Only the stable id and display name are read (the payload also carries phone/email, which are intentionally not surfaced).

All four use typed errors (AuthRequiredError when anonymous, CommandExecutionError on HTTP, parse, or layout drift), the discriminated-union probe shape, and CDP getCookies where a cookie gate applies. No silent return, sentinel row, or clamp.

Related issue: refs #1876 (the four single-site TODOs).

Type of Change

  • Bug fix
  • New feature
  • New site adapter
  • Documentation
  • Refactor
  • CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

Verified on logged-in sessions (values below are placeholders, not real account data):

opencli nowcoder whoami
  logged_in: true, site: nowcoder, user_id: "100000001", nickname: "example_user"

opencli jike whoami
  logged_in: true, site: jike, user_id: "100000002", screen_name: "Example", username: "00000000-0000-0000-0000-000000000000"

opencli maimai whoami
  logged_in: true, site: maimai, user_id: "100000003", name: "Example", company: "Example Inc"

opencli jimeng whoami
  logged_in: true, site: jimeng, user_id: "100000004", screen_name: "example_user"

Checks: npm run build, npm run check:typed-error-lint (new=0), npm run check:silent-column-drop (new=0) all pass. cli-manifest.json regenerated (adds only the 8 login/whoami command entries).

@Benjamin-eecs Benjamin-eecs marked this pull request as ready for review June 6, 2026 12:35
Copilot AI review requested due to automatic review settings June 6, 2026 12:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds browser-based authentication helpers and CLI manifest entries to support login and whoami flows for several sites (Jike, Jimeng, Maimai, Nowcoder).

Changes:

  • Introduces new auth.js modules for nowcoder/maimai/jimeng/jike that probe current identity via page evaluation + site APIs.
  • Registers new login and whoami commands for these sites in cli-manifest.json.
  • Adds lightweight polling/verification logic to detect completion of interactive logins.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
clis/nowcoder/auth.js Adds Nowcoder session detection + identity verification and registers site auth commands.
clis/maimai/auth.js Adds Maimai identity probe by parsing server-rendered inline script and registers site auth commands.
clis/jimeng/auth.js Adds Jimeng passport-based identity probe and registers site auth commands (includes polling).
clis/jike/auth.js Adds Jike identity probe using localStorage token + gateway API and registers site auth commands (includes polling).
cli-manifest.json Adds login and whoami commands for jike/jimeng/maimai/nowcoder.
Comments suppressed due to low confidence (1)

clis/maimai/auth.js:1

  • The regex captures JSON with a non-greedy \\{[\\s\\S]*?\\} which will stop at the first } and can truncate objects containing nested objects/arrays (very likely for a userObj). This will cause JSON.parse to fail and incorrectly treat logged-in sessions as anonymous. Capture the full JSON.parse argument instead of a {...} fragment (e.g., capture everything up to the closing quote/paren) and then parse that captured string.
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread clis/jike/auth.js
Comment on lines +43 to +47
poll: async (page) => {
const probe = await page.evaluate(WHOAMI_PROBE);
if (!probe?.ok) throw new AuthRequiredError('web.okjike.com', 'Waiting for Jike login');
return { user_id: probe.user_id, screen_name: probe.screen_name, username: probe.username };
},
Comment thread clis/jimeng/auth.js
Comment on lines +41 to +45
poll: async (page) => {
const probe = await page.evaluate(WHOAMI_PROBE);
if (!probe?.ok) throw new AuthRequiredError('jimeng.jianying.com', 'Waiting for Jimeng login');
return { user_id: probe.user_id, screen_name: probe.screen_name };
},
Comment thread clis/nowcoder/auth.js
Comment on lines +43 to +44
await page.goto('https://www.nowcoder.com/');
await page.wait(2);
@Benjamin-eecs Benjamin-eecs marked this pull request as draft June 6, 2026 12:43
@Benjamin-eecs Benjamin-eecs marked this pull request as ready for review June 6, 2026 12:47
Covers the four single-site login/whoami TODOs from the tracking issue, each verified against a logged-in session.

Refs jackwener#1876
@Benjamin-eecs Benjamin-eecs force-pushed the feat/auth-todo-sites branch from 7a3041f to 3deb96d Compare June 7, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants