Skip to content

Commit a692308

Browse files
committed
fix: Wait for interactive OAuth callback server to shutdown before completing OAuth flow
1 parent 6fd82ae commit a692308

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/chatbots/typescript/src/server_clients/interactive_oauth.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ export class InteractiveOAuthClient extends Server {
354354
</html>
355355
`);
356356

357-
resolve(code);
358-
setTimeout(() => server.close(), 3000);
357+
server.close(() => {
358+
resolve(code);
359+
});
359360
} else if (error) {
360361
logger.error(`Authorization error: ${error}`);
361362
res.writeHead(400, { "Content-Type": "text/html" });
@@ -367,12 +368,16 @@ export class InteractiveOAuthClient extends Server {
367368
</body>
368369
</html>
369370
`);
370-
reject(new Error(`OAuth authorization failed: ${error}`));
371+
server.close(() => {
372+
reject(new Error(`OAuth authorization failed: ${error}`));
373+
});
371374
} else {
372375
logger.error(`No authorization code or error in callback`);
373376
res.writeHead(400);
374377
res.end("Bad request");
375-
reject(new Error("No authorization code provided"));
378+
server.close(() => {
379+
reject(new Error("No authorization code provided"));
380+
});
376381
}
377382
});
378383

0 commit comments

Comments
 (0)