The "API key + console token" method is an api method. magpie's host
save() (internal/plugin/host.js, yetone/magpie 191f3c0af) stores such an
answer as {type: "api", key, metadata: {...inputs, ...result.metadata}}
and drops top-level extras, so the token sat at metadata.uaaToken. The
plugin only read auth.uaaToken / uaa_token / consoleToken, and the card
said to sign in again.
- uaaTokenOf reads the three names at the top level, then under
metadata. usernameOf reads metadata's username/accountId/email too.
- A renewed token is written back where the entry kept it (putToken):
an api entry keeps it under metadata, an oauth entry at the top level,
and nothing else in the entry changes. The host's client.auth.set
stores the body as given, with no shape it needs, so there is no
reason to lift the token out of metadata. The 401 retry uses the
same writer on a copy.
- The manual method's success result now carries metadata with the
parsed token. result.metadata overrides inputs in save(), so the
pasted cookie string (with its other session cookies) is no longer
what gets stored under metadata.uaaToken.
Tests use the exact object save() writes: the card reads for each of the
three names under metadata (usage.test.mjs), a renewal through the fake
browser writes back exactly {type:"api", key, metadata:{apiKey,
uaaToken:<renewed>}} (fake-browser.test.mjs), and the manual result's
metadata.uaaToken is the parsed token (api.test.mjs).
Run on mote, HOME=$(mktemp -d):
- 0.1.1 index.mjs with the new tests: all 3 new tests red.
- packages/inkstone bun test: 73 pass, 0 fail.
- bun scripts/check.mjs inkstone: registry.json and inkstone ok.
- root bun test: 6757 pass, 20 skip, 0 fail.
Broken by hand, each red: putToken always writing the top level (the
renewal test's write-back has a top-level uaaToken); metadata read for
uaaToken only (the uaa_token/consoleToken cases fail).
Not tried: a real InkStone account signed in with the manual method
through magpie; the 401-retry path with a metadata entry has no test of
its own.
Fixes#826
Reported-by: HuHong-Tao