feat: implement RFC 8252 system browser OIDC authentication for desktop

This commit is contained in:
ZacharyZcR
2026-05-13 19:18:44 +08:00
parent ec87f8a4d1
commit 4f23e3d22c
5 changed files with 68 additions and 3 deletions
+36
View File
@@ -1079,6 +1079,42 @@ ipcMain.handle("get-embedded-server-status", () => {
};
});
// OIDC System Browser Authentication (RFC 8252)
ipcMain.handle("oidc-system-browser-auth", async (_event, authUrl, callbackPort) => {
const http = require("http");
return new Promise((resolve, reject) => {
const server = http.createServer((req, res) => {
const url = new URL(req.url, `http://localhost:${callbackPort}`);
if (url.pathname === "/oidc-callback") {
const success = url.searchParams.get("success");
const error = url.searchParams.get("error");
const token = url.searchParams.get("token");
res.writeHead(200, { "Content-Type": "text/html" });
res.end(`<html><body><h2>${success === "true" ? "Authentication successful!" : "Authentication failed."}</h2><p>You can close this tab and return to Termix.</p><script>window.close()</script></body></html>`);
server.close();
if (success === "true") {
resolve({ success: true, token });
} else {
resolve({ success: false, error: error || "Authentication failed" });
}
}
});
server.listen(callbackPort, "127.0.0.1", () => {
shell.openExternal(authUrl);
});
// Timeout after 5 minutes
setTimeout(() => {
server.close();
reject(new Error("OIDC authentication timed out"));
}, 5 * 60 * 1000);
});
});
ipcMain.handle("get-server-config", () => {
try {
const userDataPath = app.getPath("userData");