Eight auth hooks declare rotating refresh tokens (#1027)

Eight auth hooks declare `rotating: true`: cline, codearts (and OfficeAce),
factory, minimax, nous, qoder, sensenova, workbuddy. Each package's own
code says the vendor refuses a spent refresh token. magpie then stops
carrying these sign-ins to another computer through Sync, a backup or a
Restore (internal/provider/signins_carry.go). Trae was dropped: its refresh
keeps the old token when the answer has none, and there is no evidence it
rotates. Each package's patch version is bumped (cline 0.1.15, codearts
0.3.13, factory 0.1.46, minimax 0.2.9, nous 0.1.3, qoder 0.2.66, sensenova
0.2.3, workbuddy 0.2.30). Each was checked against npm, or against
origin/dist for the dist-only packages, before the merge.

Fixes #884.

Run at cc2f9199 (a fast-forward of origin/main), on mica with a temp HOME:
bun test over the eight packages gave 1588 pass, 0 fail, and
scripts/check.mjs exited 0. CI's test and on-npm jobs pass. At 45c8fdb4,
mote gave 1834 pass with Trae included.
Not tried: a real refresh against each vendor.

Co-authored-by: yetihan <yetihan@users.noreply.github.com>
This commit is contained in:
zhou.han
2026-11-12 10:52:16 +08:00
committed by GitHub
parent 401b549fb3
commit 92c20ffef6
24 changed files with 27 additions and 10 deletions
+1
View File
@@ -1071,6 +1071,7 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
// saves what this gives (it is merged over the sign-in): only what
// changed comes back, and remember isn't called here.
refreshLead: RENEW_LEAD,
rotating: true,
refresh: (auth) =>
locked(async () => {
const a = authOf(auth)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cline-auth",
"version": "0.1.14",
"version": "0.1.15",
"description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -56,6 +56,7 @@ const due = () => ({ type: "oauth", access: "jwt1", refresh: "r1", expires: Date
test("the lead is no shorter than the check before each request", async () => {
const { hooks } = await plugin(due())
expect(hooks.auth.refreshLead).toBeGreaterThanOrEqual(5 * 60 * 1000)
expect(hooks.auth.rotating).toBe(true)
expect(typeof hooks.auth.refresh).toBe("function")
})
+2
View File
@@ -3249,6 +3249,7 @@ export const CodeArtsAuthPlugin = async ({ client } = {}, options = {}) => {
auth: {
provider: PROVIDER,
refreshLead: REFRESH_LEAD_MS,
rotating: true,
// The gateway's own cap: more in flight only queues in the plugin.
maxConcurrency: maxInflight,
@@ -4639,6 +4640,7 @@ export const OfficeAceAuthPlugin = async ({ client } = {}, options = {}) => {
icon: OFFICEACE_ICON,
maxConcurrency: 3,
refreshLead: OA_REFRESH_LEAD_MS,
rotating: true,
methods: [
{
+2
View File
@@ -3824,11 +3824,13 @@ test("a renewal never invalidates the other card's record", async () => {
oa.refreshLineages.clear()
const ca2 = await CodeArtsAuthPlugin({ client }, { fetch: ca.fetcher, ledgerPath })
assert.equal(ca2.auth.rotating, true)
const renewed = await ca2.auth.refresh(store.get(codeartsKey))
assert.equal(accessOf(renewed), "AK-1CA")
// ... and the other card's record still renews with its own token
const of = await OfficeAceAuthPlugin({ client }, { fetch: oaSts.fetcher, ledgerPath })
assert.equal(of.auth.rotating, true)
const again = await of.auth.refresh(store.get(officeaceKey))
assert.equal(accessOf(again), "AK-1OA")
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-codearts-auth",
"version": "0.3.12",
"version": "0.3.13",
"description": "Huawei Cloud in OpenCode and magpie: CodeArts (码道) and OfficeAce (AgentArts), each from its own Huawei Cloud OAuth sign-in — models, credit rates, credit usage and the daily check-in (unofficial)",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -2080,6 +2080,7 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
// spend one refresh token; that check stays for OpenCode, which
// doesn't call this
refreshLead: MAGPIE_LEAD,
rotating: true,
async refresh(auth) {
if (auth?.type !== "oauth" || !auth.access || !auth.refresh) return undefined
return locked(async () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-factory-auth",
"version": "0.1.45",
"version": "0.1.46",
"description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -53,6 +53,7 @@ test("renews a sign-in near its end, giving magpie the new tokens to save", asyn
const seen = serve()
const { hooks, sets } = await plugin(due())
expect(hooks.auth.refreshLead).toBe(3 * 60 * 1000)
expect(hooks.auth.rotating).toBe(true)
const got = await hooks.auth.refresh(due(), "factory")
expect(got).toMatchObject({ access: NEW, refresh: "r-new", expires: Math.floor(later / 1000) * 1000, activeOrganizationId: "fac_A" })
expect(got.type).toBeUndefined()
+1
View File
@@ -1070,6 +1070,7 @@ function makePlugin(site) {
// check before each request below stays for OpenCode, which
// doesn't call this
refreshLead: LEAD_MS,
rotating: true,
async refresh(auth) {
if (auth?.type !== "oauth" || !auth.access || !auth.refresh) return undefined
const a = latest(site, auth)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-minimax-auth",
"version": "0.2.8",
"version": "0.2.9",
"description": "OpenCode provider plugins for MiniMax Code accounts: their credits and M Plan, China (minimax-code) and international (minimax-code-global), with MiniMax Code's own device sign-in",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -139,6 +139,7 @@ test("magpie renews the sign-in ahead of its end through auth.refresh, once with
const s = store({ access: "old", refresh: "r1", expires: Date.now() - 1 })
const hooks = await MiniMaxCodeAuthPlugin({ client: s.client })
expect(hooks.auth.refreshLead).toBe(10 * 60 * 1000)
expect(hooks.auth.rotating).toBe(true)
// magpie's renewal and a request's own check, at once
const [got, res] = await Promise.all([hooks.auth.refresh({ ...s.auth }, "minimax-code"), chat(await hooks.auth.loader(s.getAuth))])
expect(got).toMatchObject({ access: "new", refresh: "r2" })
+1 -1
View File
@@ -111,7 +111,7 @@ export async function NousPortalAuthPlugin({ client }) {
},
},
auth: {
provider: ID, icon: "nousresearch", refreshLead: LEAD,
provider: ID, icon: "nousresearch", refreshLead: LEAD, rotating: true,
refresh: auth.refresh,
async loader(getAuth) {
if ((await auth.read(getAuth))?.type !== "oauth") return {}
+1
View File
@@ -327,6 +327,7 @@ test("one entrypoint, distinct provider id, non-destructive config and standard
assert.equal(config.provider[ID].name, "Custom label")
assert.equal(config.provider[ID].models.custom.name, "Mine")
assert.equal(hooks.auth.refreshLead, LEAD)
assert.equal(hooks.auth.rotating, true)
assert.deepEqual(await hooks.auth.loader(async () => ({ type: "api", key: "unrelated" })), {})
assert.equal((await hooks.auth.loader(s.get)).apiKey, "nous-portal-oauth")
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-nous-auth",
"version": "0.1.2",
"version": "0.1.3",
"description": "Nous Portal OAuth with device sign-in and automatic token renewal in OpenCode and magpie",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -3797,6 +3797,7 @@ const makePlugin = (site) => async ({ client }) => {
// doesn't call this. The device token of a job-token account has no
// end on record: usage rotates it once Qoder refuses it, as before.
refreshLead: RENEW_LEAD,
rotating: true,
async refresh(auth) {
// a Lingma 1.0 account: the IDE's newer token, when it has one;
// nothing when it hasn't yet (fresh says so once it is needed)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.65",
"version": "0.2.66",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -59,6 +59,7 @@ for (const site of SITES) {
const calls = serve(site)
const { hooks, sets } = await plugin(site, account())
expect(hooks.auth.refreshLead).toBe(10 * 60 * 1000)
expect(hooks.auth.rotating).toBe(true)
const got = await hooks.auth.refresh(account(), { id: site.name })
expect(got).toMatchObject({ access: "jt-2", refresh: "jrt-2" })
// the renewal also names the account (the phone, not its uuid), so an
+1
View File
@@ -328,6 +328,7 @@ export async function SenseNovaAuthPlugin({ client, magpie } = {}, options = {})
auth: {
provider: PROVIDER_ID,
refreshLead: EARLY_MS,
rotating: true,
maxConcurrency: 1,
options: [
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-sensenova-auth",
"version": "0.2.2",
"version": "0.2.3",
"description": "SenseNova (SenseTime 日日新) Token Plan in OpenCode and magpie: browser or password sign-in for the credit pools, windows and grants, plus the plan's models through a Token Plan API key",
"type": "module",
"main": "./opencode.mjs",
+2 -1
View File
@@ -106,6 +106,7 @@ test("a refresh token is renewed, and the new one replaces the old", async () =>
return json({ access_token: "jwt-2", refresh_token: "new-r", expires_in: 10800 })
})
const p = await SenseNovaAuthPlugin({ client: { auth: { set: async () => {} } } })
expect(p.auth.rotating).toBe(true)
const renewed = await p.auth.refresh({ type: "oauth", access: "old", refresh: "old-r", expires: Date.now() + 1000 })
expect(await unseal(renewed.access)).toBe("jwt-2")
expect(await unseal(renewed.refresh)).toBe("new-r")
@@ -299,4 +300,4 @@ test("a Windows session whose DPAPI refuses still refreshes, storing plaintext a
} finally {
_setCryptoForTests(null)
}
})
})
+1
View File
@@ -3919,6 +3919,7 @@ function makePlugin(site) {
// which doesn't call this. Desktop's sign-in has no expiry stored
// and is renewed as before.
refreshLead: LEAD_MS,
rotating: true,
refresh: (auth) => refreshed(site, auth),
// the account's daily check-in: magpie can run it once a day per
// account, when its WorkBuddy check-in switch is on; the button in
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.2.29",
"version": "0.2.30",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./opencode.mjs",
+1
View File
@@ -45,6 +45,7 @@ test("auth.refresh renews and gives the new fields, saving nothing itself", asyn
const sets = []
const hooks = await WorkBuddyAIAuthPlugin({ client: { auth: { set: async (x) => sets.push(x) } } })
expect(hooks.auth.refreshLead).toBeGreaterThanOrEqual(60 * 1000)
expect(hooks.auth.rotating).toBe(true)
const got = await hooks.auth.refresh(auth(), "workbuddy-ai")
expect(got.access).toBe("new")
expect(got.refresh).toBe("r2")