fix(oauth): refresh Cline tokens with extension JSON contract

This commit is contained in:
Paulo Schuller
2026-08-16 12:32:25 -03:00
committed by decolua
parent bb3cb43e09
commit 88676b3037
3 changed files with 78 additions and 9 deletions

View File

@@ -102,19 +102,38 @@ describe("refreshAccessToken — config-driven profiles", () => {
expect(fm).toHaveBeenCalledTimes(1);
});
});
describe("refreshAccessToken — legacy generic path (no profile)", () => {
describe("Cline refresh", () => {
beforeEach(() => { vi.clearAllMocks(); vi.resetModules(); global.fetch = originalFetch; });
afterEach(() => { global.fetch = originalFetch; });
it("still works for an unprofiled provider via config.refreshUrl/clientId/clientSecret", async () => {
const fm = mockFetchOnce({ access_token: "gen-acc", expires_in: 3600 });
const { refreshAccessToken } = await import("open-sse/services/tokenRefresh/providers.js");
it("uses the extension JSON refresh contract", async () => {
const expiresAt = new Date(Date.now() + 3600 * 1000).toISOString();
const fm = mockFetchOnce({
data: {
accessToken: "cline-acc",
refreshToken: "cline-rot",
expiresAt,
},
});
const { refreshTokenByProvider } = await import(
"open-sse/services/tokenRefresh.js"
);
await refreshAccessToken("cline", "gen-old", {}, console);
const out = await refreshTokenByProvider(
"cline",
{ refreshToken: "cline-old" },
console
);
const body = new URLSearchParams(fm.mock.calls[0][1].body);
expect(body.get("grant_type")).toBe("refresh_token");
expect(body.get("client_id")).toBeTruthy();
const [, init] = fm.mock.calls[0];
expect(init.headers["Content-Type"]).toBe("application/json");
expect(JSON.parse(init.body)).toEqual({
refreshToken: "cline-old",
grantType: "refresh_token",
clientType: "extension",
});
expect(out.accessToken).toBe("cline-acc");
expect(out.refreshToken).toBe("cline-rot");
expect(out.expiresIn).toBeGreaterThan(0);
});
});