da079585d9cdd1fcbedfcfc60bbff316efe5e76a
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
0a8e5abd00 |
qoder 0.2.21: Qoder CN PAT sign-in, and a PAT account checks in on its job token (#262, sphuang1030-prog)
Qoder CN offers the PAT sign-in too (its /api/v1/jobToken/exchange takes a personal_token as qoder.com's does; the prompt names qoder.cn's console), and a PAT account, which has no device token, signs the campaigns pages and the daily check-in with its job token instead of rotating a device token it doesn't have. The account keeps the name its browser sign-in takes (email || uid), so a renewed PAT sign-in replaces its lapsed row. Run at d7db9f2b987c46cbf100cda9d89a8a546e374fb6: - bun test packages/qoder: 155 pass, 0 fail; bun scripts/check.mjs passes. - The PR's check-in tests go through the loader's campaigns fetch, not auth.checkin. Two local tests calling auth.checkin with a PAT account (qoder and qoder-cn: claimed on the job token, no deviceToken refresh; a 403 is "failed", not rotated) pass on this head and both fail with the checkin hook's change reverted by hand. They follow on main. - Probe: POST openapi.qoder.com.cn/api/v1/jobToken/exchange with an invalid pt- token answers 400 BadRequest, as openapi.qoder.sh does (an unknown path answers 401), so the endpoint exists on CN and a bad PAT maps to "refused the PAT". qoder.cn/account/integrations redirects to sign-in, as qoder.com's does. - Not tried: a live qoder.cn PAT exchange, chat or claim; that rests on the author's live run. |
||
|
|
a6f09a0e9a |
qoder: add PAT (Personal Access Token) sign-in method (#103)
* qoder: add PAT (Personal Access Token) sign-in method
Add a new auth method that exchanges a PAT for a job token via
/api/v1/jobToken/exchange, bypassing the OAuth device flow. PATs are
long-lived (up to 1 year), avoiding the ~3-day re-authentication cycle
of OAuth refresh tokens.
Changes:
- Add patSignIn function for PAT → job token exchange
- Add "Sign in with Qoder PAT" method with password prompt
- Handle PAT accounts in usage (no device token available)
- Add pat.test.mjs with 10 tests covering both sites
- Update vpc.test.mjs for new method count
* qoder: use text prompt type for PAT (magpie has no password type)
magpie's prompt system only supports "text" and "select" types.
Change the PAT prompt from "password" to "text" to match.
* qoder: use password prompt type for PAT input
Now that magpie supports "password" prompt type, use it for PAT input
so the token is masked when typed in both GUI and TUI.
* qoder: address PR review — PAT kept, fields read as Qoder's client does
1. Store the PAT on the credential; when the job refresh lapses
(SignInGone from refreshJob), re-exchange the PAT instead of
marking the account signed out. The PAT lasts a year, the refresh
two days.
2. Read the exchange response as Qoder's client does:
- token from token, device_token or access_token
- refresh from refresh_token or refreshToken
- expiry from expire_time or expires_at (date) first, then
expires_in in seconds (not milliseconds)
3. Use the openapi() helper for the exchange (no custom User-Agent);
400/401/403 say "refused the PAT" rather than passing through the
raw body.
4. Try the usage endpoint with the job token for PAT accounts; fall
back to the "PAT" plan label if it won't accept it.
5. Exclude the PAT method from Qoder CN: its CLI uses device chat
directly and never makes a job token, so a PAT exchange may not
produce one the chat endpoint accepts.
* qoder: fix expires_in unit — milliseconds, not seconds
The real exchange response shows expires_in: 86400000 (24h in ms),
not 86400 (seconds). The expires_at date field takes precedence in
exchangeExpiry, so the fallback was not hit in practice, but correct
it for completeness.
* qoder: drive the renew test through the real refresh path, usage through fetchUsage
The renew test called the PAT sign-in directly, so it never met the
fallback it was named for. It now loads a stored expired credential
whose job refresh is refused, and checks the exchange is asked with the
stored PAT, the request goes on with the new token, and the saved
credential still carries the PAT — and fails when the fallback is
taken out. A second case keeps no PAT on the credential and expects
the sign-in gone to come out.
The PAT branch of usage built fetchUsage's request by hand and turned
every error into a plan of its own; it calls fetchUsage now, its
errors surfacing as the device path's do. A live PAT account answered
the usage endpoint 200 with a qoder envelope on the job token from the
exchange, said so in the comment there.
* qoder: a refused PAT re-exchange ends the sign-in
The renew fallback let a refused PAT through as a plain error, which
magpie read as a server fault and kept the account on. A PAT lapses
like a device sign-in does — expired, or revoked — so renew turns the
exchange's refusal into a lapsed sign-in: usage says "expired" and the
request answers 401, asking for a new PAT. Interactive sign-in keeps
the plain error.
|