This commit is contained in:
Junghwan 2026-04-22 22:50:26 -07:00 committed by GitHub
commit 56a2a04e44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,7 +29,7 @@ export function createAuthServer(
onCallback: (callbackUrl: URL) => void | Promise<void> onCallback: (callbackUrl: URL) => void | Promise<void>
): Promise<AuthServerResult> { ): Promise<AuthServerResult> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const server = createServer((req, res) => { const server = createServer(async (req, res) => {
if (!req.url) { if (!req.url) {
res.writeHead(400); res.writeHead(400);
res.end('Bad Request'); res.end('Bad Request');
@ -64,27 +64,51 @@ export function createAuthServer(
return; return;
} }
// Handle callback - pass full URL so params like iss (OpenID Connect) are preserved for token exchange try {
onCallback(url); // Handle callback - pass full URL so params like iss (OpenID Connect)
// are preserved for token exchange.
await onCallback(url);
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(` res.end(`
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Authorization Successful</title> <title>Authorization Successful</title>
<style> <style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; } body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
.success { color: #2e7d32; } .success { color: #2e7d32; }
</style> </style>
</head> </head>
<body> <body>
<h1 class="success">Authorization Successful</h1> <h1 class="success">Authorization Successful</h1>
<p>You can close this window.</p> <p>You can close this window.</p>
<script>setTimeout(() => window.close(), 2000);</script> <script>setTimeout(() => window.close(), 2000);</script>
</body> </body>
</html> </html>
`); `);
} catch (callbackError) {
const message = callbackError instanceof Error ? callbackError.message : String(callbackError);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>OAuth Error</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
.error { color: #d32f2f; }
</style>
</head>
<body>
<h1 class="error">Authorization Failed</h1>
<p>Error: ${escapeHtml(message)}</p>
<p>You can close this window.</p>
<script>setTimeout(() => window.close(), 3000);</script>
</body>
</html>
`);
}
} else { } else {
res.writeHead(404); res.writeHead(404);
res.end('Not Found'); res.end('Not Found');
@ -104,4 +128,3 @@ export function createAuthServer(
}); });
}); });
} }