trae: an enterprise seat signs in on its console's own authorization page (#1328)
Since the 2026-11-18 Doubao/Feishu account upgrade, www.trae.cn/authorization
sends a signed-out browser to accounts.doubao.com ("登录豆包飞书账号 以继续使用
TRAE"), which has no enterprise entry: hide_saas_login is lost on the way,
and a legacy enterprise TRAE account (email/password) can't sign in there at
all (@yalifesign on X; #1328, Jinzhengxu, yjun123).
Each provider now has a second way, "Trae CN enterprise account (browser)" /
"Trae Global enterprise account (browser)". It opens
console.enterprise.trae.cn/authorization (console.enterprise.trae.ai for
Global) with the same parameters as the consumer page. That route is in the
consoles' own page code (CN index-Jt0RvTT_.js, Global index-Cd9NoAem.js): it
takes login_trace_id, device_id, auth_from (trae/solo/...) and an
auth_callback_url on 127.0.0.1, shows the console's login (TRAE account,
Doubao/Feishu, 企业 SSO) when signed out, then calls back with userJwt,
userInfo, refreshToken and host (its Api host) - the fields the plugin
already reads. A callback from the console that names no host takes its
consoleHost, so the seat is still enterprise. The personal way is unchanged.
Run (mote, through mote-run):
- packages/trae: bun test, 293 pass, 0 fail.
- root bun test with a temp HOME: 9101 pass, 0 fail (9121 tests, 638
files, 573s); bun scripts/check.mjs exit 0. Both at base 140c513b; rebased onto
e6c45711 (factory, agy-cli, kiro only), packages/trae and check.mjs ran
again at the pushed head: 293 pass, 0 fail, exit 0.
Broken by hand: pointing the enterprise way back at hosts.web and dropping
the consoleHost fallback turns "the enterprise way opens the console's
authorization page ..." and "a console callback naming no host ..." red
(29 pass, 2 fail in enterprise.test.mjs).
Not tried: a real enterprise seat on either console (none here), and
whether the console's page keeps auth_from=solo through its own SSO
redirect. Global's consumer page was not checked for the same change.
This commit is contained in:
+18
-2
@@ -30,8 +30,9 @@ A fix to that machinery reaches both.
|
||||
|
||||
## Sign-in
|
||||
|
||||
One way per provider, **Trae CN account (browser)** or **Trae Global account
|
||||
(browser)**. The plugin opens that realm's authorization page
|
||||
A personal account signs in with **Trae CN account (browser)** or **Trae
|
||||
Global account (browser)**; an enterprise seat has its own way (see
|
||||
Enterprise below). The plugin opens that realm's authorization page
|
||||
(`www.trae.cn/authorization` or `www.trae.ai/authorization`, the IDE's client
|
||||
`ono9krqynydwx5`). Sign in there and allow the sign-in; the page then sends the
|
||||
browser back to a callback on `http://127.0.0.1:<port>/authorize` — it accepts
|
||||
@@ -51,6 +52,21 @@ Trae Global's stays 19. The daily check-in goes on a 15-digit id made from it
|
||||
|
||||
### Enterprise (SaaS) accounts
|
||||
|
||||
Each provider has a second way, **Trae CN enterprise account (browser)** or
|
||||
**Trae Global enterprise account (browser)**, since 0.2.46. It opens the
|
||||
realm's enterprise console's own authorization page
|
||||
(`console.enterprise.trae.cn/authorization` or
|
||||
`console.enterprise.trae.ai/authorization`) with the same parameters and
|
||||
callback. There the seat signs in with its TRAE enterprise email and
|
||||
password, the Doubao/Feishu tab, or the company's SSO. Since November 2026
|
||||
trae.cn's own page sends a signed-out browser to a Doubao/Feishu account
|
||||
sign-in (accounts.doubao.com) that has no way to an enterprise seat, so an
|
||||
enterprise account signing in again there was not recognised (@yalifesign
|
||||
on X). The console's page calls back with `userJwt`, `userInfo`,
|
||||
`refreshToken` and `host` (its Api host), read as below; a callback naming
|
||||
no host is taken as the console's seat. Read from the consoles' page code;
|
||||
**not tried with a real enterprise seat**.
|
||||
|
||||
Since 0.2.10 the authorization page also offers Trae's enterprise (SaaS / SSO)
|
||||
sign-in; before, the plugin asked the page to hide it (`hide_saas_login`), so
|
||||
an enterprise subscription could only sign in as a personal account. A host
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// Not tried with a real enterprise account: the hosts below are made up.
|
||||
import "./nonet.mjs"
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
|
||||
import { TraeCNAuthPlugin, TraeGlobalAuthPlugin, _internal } from "./index.mjs"
|
||||
import { fakeTrae, json, signedIn, sse } from "./fake.mjs"
|
||||
|
||||
// the console's own answer, as a real enterprise account's is: the seat
|
||||
@@ -67,6 +67,83 @@ test("the sign-in page doesn't hide the enterprise (SaaS) sign-in", async () =>
|
||||
await a.callback()
|
||||
})
|
||||
|
||||
// Since November 2026 trae.cn's authorization page sends a signed-out
|
||||
// browser to a Doubao/Feishu account sign-in with no way to an enterprise
|
||||
// one (@yalifesign on X). The enterprise way starts on the realm's console's
|
||||
// own authorization page, which takes the same parameters and calls back the
|
||||
// same way, naming its Api host (console.enterprise.trae.cn's code, read
|
||||
// 2026-11-19; not tried with a real seat).
|
||||
test("the enterprise way opens the console's authorization page with the IDE's parameters", async () => {
|
||||
for (const [make, site] of [[TraeCNAuthPlugin, CN], [TraeGlobalAuthPlugin, GLOBAL]]) {
|
||||
const hooks = await make({ client: {} })
|
||||
const m = hooks.auth.methods[1]
|
||||
expect(m.type).toBe("oauth")
|
||||
expect(m.label).toBe(`${site.name} enterprise account (browser)`)
|
||||
const a = await m.authorize()
|
||||
const u = new URL(a.url)
|
||||
expect(u.origin).toBe(site.hosts.console)
|
||||
expect(u.pathname).toBe("/authorization")
|
||||
// what the console's page checks before it calls back
|
||||
for (const k of ["auth_from", "login_trace_id", "device_id", "auth_callback_url"]) expect(u.searchParams.get(k)).toBeTruthy()
|
||||
expect(["trae", "solo"]).toContain(u.searchParams.get("auth_from"))
|
||||
expect(new URL(u.searchParams.get("auth_callback_url")).hostname).toBe("127.0.0.1")
|
||||
await fetch(u.searchParams.get("auth_callback_url") + "?error=x")
|
||||
expect(await a.callback()).toEqual({ type: "failed", error: "x" })
|
||||
// the personal way is still the consumer site's
|
||||
const p = await hooks.auth.methods[0].authorize()
|
||||
expect(new URL(p.url).origin).toBe(site.hosts.web)
|
||||
await fetch(new URL(p.url).searchParams.get("auth_callback_url") + "?error=x")
|
||||
await p.callback()
|
||||
}
|
||||
})
|
||||
|
||||
test("the console's callback signs in an enterprise seat on its console", async () => {
|
||||
f = fakeTrae()
|
||||
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||
const a = await hooks.auth.methods[1].authorize()
|
||||
const q = new URL(a.url).searchParams
|
||||
// the console's callback: _t() in its authorization page
|
||||
const url = new URL(q.get("auth_callback_url"))
|
||||
const exp = Math.floor(Date.now() / 1000) + 7200
|
||||
for (const [k, v] of Object.entries({
|
||||
scope: "saas", host: ENT, consoleHost: ENT, coreHost: ENT, isRedirect: "true", loginTraceID: q.get("login_trace_id"),
|
||||
userJwt: JSON.stringify({ Token: "jwt-e", TokenExpireAt: exp }),
|
||||
userInfo: JSON.stringify({ UserID: "u-e", ScreenName: "Acme", TenantID: "t-1" }),
|
||||
refreshToken: "r-e", refreshExpireAt: String(exp + 86400), data: "r-e",
|
||||
})) url.searchParams.set(k, v)
|
||||
await fetch(url)
|
||||
const got = await a.callback()
|
||||
expect(got.type).toBe("success")
|
||||
expect(got.access).toBe("jwt-e")
|
||||
expect(got.refresh).toBe("r-e")
|
||||
expect(got.host).toBe(ENT)
|
||||
expect(_internal.isEnterprise(got, CN)).toBe(true)
|
||||
expect(CN.apiOf(got)).toBe(CN.hosts.console)
|
||||
expect(got.deviceId).toBe(q.get("device_id"))
|
||||
})
|
||||
|
||||
test("a console callback naming no host keeps its console as the seat's host", async () => {
|
||||
f = fakeTrae()
|
||||
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||
const a = await hooks.auth.methods[1].authorize()
|
||||
const url = new URL(new URL(a.url).searchParams.get("auth_callback_url"))
|
||||
url.searchParams.set("consoleHost", ENT)
|
||||
url.searchParams.set("userJwt", JSON.stringify({ Token: "jwt-e", TokenExpireAt: Math.floor(Date.now() / 1000) + 7200 }))
|
||||
url.searchParams.set("refreshToken", "r-e")
|
||||
await fetch(url)
|
||||
const got = await a.callback()
|
||||
expect(got.host).toBe(ENT)
|
||||
expect(_internal.isEnterprise(got, CN)).toBe(true)
|
||||
// the consumer page's callback is not read that way
|
||||
const p = await hooks.auth.methods[0].authorize()
|
||||
const pu = new URL(new URL(p.url).searchParams.get("auth_callback_url"))
|
||||
pu.searchParams.set("consoleHost", ENT)
|
||||
pu.searchParams.set("userJwt", JSON.stringify({ Token: "jwt-p", TokenExpireAt: Math.floor(Date.now() / 1000) + 7200 }))
|
||||
pu.searchParams.set("refreshToken", "r-p")
|
||||
await fetch(pu)
|
||||
expect(_internal.isEnterprise(await p.callback(), CN)).toBe(false)
|
||||
})
|
||||
|
||||
test("only an https host on Trae's own domains is taken", () => {
|
||||
const t = _internal.traeHost
|
||||
expect(t("https://trae-api-cn.mchost.guru")).toBe("https://trae-api-cn.mchost.guru")
|
||||
|
||||
+25
-8
@@ -755,10 +755,12 @@ const page = (ok, title, text) => `<!doctype html><meta charset="utf-8"><meta na
|
||||
// signedIn reads trae.cn's callback: userJwt (the token pair) and userInfo
|
||||
// (the account), or, from its older page, a refresh token alone, which is
|
||||
// exchanged for the pair
|
||||
async function signedIn(q, device, site) {
|
||||
async function signedIn(q, device, site, { enterprise = false } = {}) {
|
||||
const jwt = parseJSON(q.get("userJwt"))
|
||||
const info = parseJSON(q.get("userInfo"))
|
||||
const host = q.get("host") || info.Host || ""
|
||||
// the enterprise console's page names its Api host; one that names none
|
||||
// still names its console, which is the seat's host
|
||||
const host = q.get("host") || info.Host || (enterprise ? q.get("consoleHost") || "" : "")
|
||||
let s = {
|
||||
token: jwt.Token ?? jwt.token ?? "",
|
||||
refresh: jwt.RefreshToken ?? jwt.refreshToken ?? q.get("refreshToken") ?? "",
|
||||
@@ -793,8 +795,18 @@ async function signedIn(q, device, site) {
|
||||
}
|
||||
|
||||
// browserSignIn is the IDE's sign-in: trae.cn's authorization page, back
|
||||
// to a callback on 127.0.0.1 (the page takes no other kind)
|
||||
async function browserSignIn(site) {
|
||||
// to a callback on 127.0.0.1 (the page takes no other kind).
|
||||
//
|
||||
// enterprise opens the realm's enterprise console's own authorization page
|
||||
// (console.enterprise.trae.cn/authorization, the same parameters and the
|
||||
// same callback) instead of the consumer site's. Since November 2026 trae.cn's
|
||||
// page sends a signed-out browser to a Doubao/Feishu account sign-in
|
||||
// (accounts.doubao.com) with no way to an enterprise one, so a seat that
|
||||
// signs in with its TRAE enterprise email, the console's Doubao/Feishu tab
|
||||
// or the tenant's SSO has to start on the console (@yalifesign on X). The
|
||||
// console's page calls back with userJwt, userInfo, refreshToken and host
|
||||
// (its own Api host), which signedIn reads as before.
|
||||
async function browserSignIn(site, { enterprise = false } = {}) {
|
||||
const device = newDevice(site)
|
||||
const trace = randomUUID()
|
||||
let over = false
|
||||
@@ -824,7 +836,7 @@ async function browserSignIn(site) {
|
||||
}
|
||||
if (!q.get("userJwt") && !q.get("refreshToken")) return html(page(false, "Nothing to sign in with", `${site.webHost} sent no token; start the sign-in again.`))
|
||||
try {
|
||||
const s = await signedIn(q, device, site)
|
||||
const s = await signedIn(q, device, site, { enterprise })
|
||||
finish({ ...toAuth(s, site), type: "success" })
|
||||
html(page(true, "You're signed in", `${s.name || s.uid || `Your ${site.name} account`} is signed in. You can close this tab.`))
|
||||
} catch (e) {
|
||||
@@ -867,8 +879,10 @@ async function browserSignIn(site) {
|
||||
hide_saas_login: "false",
|
||||
})
|
||||
return {
|
||||
url: `${site.hosts.web}/authorization?${q}`,
|
||||
instructions: `Sign in to ${site.name} (${site.webHost}) in the browser and allow the sign-in. It finishes here by itself.`,
|
||||
url: `${enterprise ? site.hosts.console : site.hosts.web}/authorization?${q}`,
|
||||
instructions: enterprise
|
||||
? `Sign in to your ${site.name} enterprise seat in the browser (enterprise email, Doubao/Feishu or your company's SSO) and allow the sign-in. It finishes here by itself.`
|
||||
: `Sign in to ${site.name} (${site.webHost}) in the browser and allow the sign-in. It finishes here by itself.`,
|
||||
method: "auto",
|
||||
callback: () => done,
|
||||
}
|
||||
@@ -4383,7 +4397,10 @@ const makePlugin = (site) => async ({ client }) => {
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: [{ type: "oauth", label: `${site.name} account (browser)`, authorize: () => browserSignIn(site) }],
|
||||
methods: [
|
||||
{ type: "oauth", label: `${site.name} account (browser)`, authorize: () => browserSignIn(site) },
|
||||
{ type: "oauth", label: `${site.name} enterprise account (browser)`, authorize: () => browserSignIn(site, { enterprise: true }) },
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-trae-auth",
|
||||
"version": "0.2.45",
|
||||
"version": "0.2.46",
|
||||
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user