Skip to content

Commit 18eab05

Browse files
MatthewSchledersteipete
authored andcommitted
fix(minimax): use account oauth endpoints
1 parent bf777b9 commit 18eab05

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

‎extensions/minimax/oauth.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,67 @@ describe("normalizeOAuthExpires", () => {
2929
});
3030

3131
describe("loginMiniMaxPortalOAuth", () => {
32+
it("uses MiniMax account OAuth endpoints directly for global and CN login", async () => {
33+
for (const [region, expectedHosts] of [
34+
[
35+
"global",
36+
[
37+
"https://account.minimax.io/oauth2/device/code",
38+
"https://account.minimax.io/oauth2/token",
39+
],
40+
],
41+
[
42+
"cn",
43+
[
44+
"https://account.minimaxi.com/oauth2/device/code",
45+
"https://account.minimaxi.com/oauth2/token",
46+
],
47+
],
48+
] as const) {
49+
const requestedUrls: string[] = [];
50+
const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
51+
requestedUrls.push(String(input));
52+
const body =
53+
init?.body instanceof URLSearchParams
54+
? init.body
55+
: new URLSearchParams(typeof init?.body === "string" ? init.body : "");
56+
if (requestedUrls.length === 1) {
57+
return new Response(
58+
JSON.stringify({
59+
user_code: "CODE",
60+
verification_uri: "https://example.com/device",
61+
expired_in: Date.now() + 10_000,
62+
state: body.get("state"),
63+
}),
64+
{ status: 200, headers: { "Content-Type": "application/json" } },
65+
);
66+
}
67+
return new Response(
68+
JSON.stringify({
69+
status: "success",
70+
access_token: "access",
71+
refresh_token: "refresh",
72+
expired_in: 3600,
73+
}),
74+
{ status: 200, headers: { "Content-Type": "application/json" } },
75+
);
76+
});
77+
vi.stubGlobal("fetch", fetchMock);
78+
79+
await expect(
80+
loginMiniMaxPortalOAuth({
81+
region,
82+
openUrl: vi.fn(async () => undefined),
83+
note: vi.fn(async () => undefined),
84+
progress: { update: vi.fn(), stop: vi.fn() },
85+
}),
86+
).resolves.toMatchObject({ access: "access", refresh: "refresh" });
87+
expect(requestedUrls).toEqual(expectedHosts);
88+
89+
vi.unstubAllGlobals();
90+
}
91+
});
92+
3293
it("rejects Date-invalid authorization expiries before formatting instructions", async () => {
3394
const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
3495
const body =

‎extensions/minimax/oauth.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export type MiniMaxRegion = "cn" | "global";
1414
const MINIMAX_OAUTH_CONFIG = {
1515
cn: {
1616
baseUrl: "https://api.minimaxi.com",
17+
oauthBaseUrl: "https://account.minimaxi.com",
1718
clientId: "78257093-7e40-4613-99e0-527b14b39113",
1819
},
1920
global: {
2021
baseUrl: "https://api.minimax.io",
22+
oauthBaseUrl: "https://account.minimax.io",
2123
clientId: "78257093-7e40-4613-99e0-527b14b39113",
2224
},
2325
} as const;
@@ -30,11 +32,11 @@ const MINIMAX_ABSOLUTE_EXPIRY_MS_THRESHOLD = 1_000_000_000_000;
3032
function getOAuthEndpoints(region: MiniMaxRegion) {
3133
const config = MINIMAX_OAUTH_CONFIG[region];
3234
return {
33-
codeEndpoint: `${config.baseUrl}/oauth/code`,
34-
tokenEndpoint: `${config.baseUrl}/oauth/token`,
35+
codeEndpoint: `${config.oauthBaseUrl}/oauth2/device/code`,
36+
tokenEndpoint: `${config.oauthBaseUrl}/oauth2/token`,
3537
clientId: config.clientId,
3638
baseUrl: config.baseUrl,
37-
hostname: new URL(config.baseUrl).hostname,
39+
hostname: new URL(config.oauthBaseUrl).hostname,
3840
};
3941
}
4042

0 commit comments

Comments
 (0)