8c4bf5cc7239f4cd2fd75d7e4e857deabe389f6c
1
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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.
|