fix(oauth): refresh Cline tokens with extension JSON contract
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user