Skip to content

Commit 2d98129

Browse files
committed
revert: keep original OAuth polling loop logic
Revert unnecessary changes to the OAuth device flow polling loop. The original while(true) loop with setTimeout positioning works fine and doesn't need to be changed for enterprise support.
1 parent c98130b commit 2d98129

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

index.mjs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,7 @@ export async function CopilotAuthPlugin({ client }) {
204204
instructions: `Enter code: ${deviceData.user_code}`,
205205
method: "auto",
206206
callback: async () => {
207-
const maxAttempts = Math.ceil(
208-
(deviceData.expires_in || 900) / (deviceData.interval || 5)
209-
);
210-
let attempts = 0;
211-
212-
while (attempts < maxAttempts) {
213-
await new Promise((resolve) =>
214-
setTimeout(resolve, (deviceData.interval || 5) * 1000)
215-
);
216-
207+
while (true) {
217208
const response = await fetch(urls.ACCESS_TOKEN_URL, {
218209
method: "POST",
219210
headers: {
@@ -250,15 +241,19 @@ export async function CopilotAuthPlugin({ client }) {
250241
}
251242

252243
if (data.error === "authorization_pending") {
253-
attempts++;
244+
await new Promise((resolve) =>
245+
setTimeout(resolve, deviceData.interval * 1000),
246+
);
254247
continue;
255248
}
256249

257250
if (data.error) return { type: "failed" };
258-
}
259251

260-
// Timeout
261-
return { type: "failed" };
252+
await new Promise((resolve) =>
253+
setTimeout(resolve, deviceData.interval * 1000),
254+
);
255+
continue;
256+
}
262257
},
263258
};
264259
},

0 commit comments

Comments
 (0)