Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(auth): initiate desktop OAuth from browser, not renderer (#692)

Gabriel Steindb4db2c3994d
diff --git a/main.js b/main.js
index 4b9cb272b..511544781 100644
--- a/main.js
+++ b/main.js
@@ -392,6 +392,7 @@ function initializeCoreManagers() {
meetingAecManager,
getTrayManager: () => trayManager,
oauthProtocolRegistered: protocolRegistered,
+ oauthProtocol: OAUTH_PROTOCOL,
});
}
@@ -774,8 +775,7 @@ async function startApp() {
// TODO: drop legacy REASONING_PROVIDER / LOCAL_REASONING_MODEL fallbacks after 2 releases.
const cleanupProvider = process.env.CLEANUP_PROVIDER || process.env.REASONING_PROVIDER;
- const cleanupLocalModel =
- process.env.LOCAL_CLEANUP_MODEL || process.env.LOCAL_REASONING_MODEL;
+ const cleanupLocalModel = process.env.LOCAL_CLEANUP_MODEL || process.env.LOCAL_REASONING_MODEL;
if (cleanupProvider === "local" && cleanupLocalModel) {
const modelManager = require("./src/helpers/modelManagerBridge").default;
modelManager.prewarmServer(cleanupLocalModel).catch((err) => {
diff --git a/preload.js b/preload.js
index e82826a53..eac91159c 100644
--- a/preload.js
+++ b/preload.js
@@ -306,6 +306,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
getAppVersion: () => ipcRenderer.invoke("get-app-version"),
getPostMigrationState: () => ipcRenderer.invoke("get-post-migration-state"),
getOAuthProtocolRegistered: () => ipcRenderer.invoke("get-oauth-protocol-registered"),
+ getOAuthProtocol: () => ipcRenderer.invoke("get-oauth-protocol"),
markBundleMigrated: () => ipcRenderer.invoke("mark-bundle-migrated"),
markBundleMigrationDismissed: () => ipcRenderer.invoke("mark-bundle-migration-dismissed"),
getUpdateStatus: () => ipcRenderer.invoke("get-update-status"),
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index e247c5b39..8b3212503 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -298,6 +298,7 @@ class IPCHandlers {
this.linuxPortalAudioManager = managers.linuxPortalAudioManager;
this.meetingAecManager = managers.meetingAecManager;
this.oauthProtocolRegistered = managers.oauthProtocolRegistered === true;
+ this.oauthProtocol = managers.oauthProtocol || "openwhispr";
this.sessionId = crypto.randomUUID();
this.assemblyAiStreaming = null;
this.deepgramStreaming = null;
@@ -6387,6 +6388,8 @@ class IPCHandlers {
ipcMain.handle("get-oauth-protocol-registered", () => this.oauthProtocolRegistered);
+ ipcMain.handle("get-oauth-protocol", () => this.oauthProtocol);
+
ipcMain.handle("mark-bundle-migrated", () => {
postMigrationDetector.markBundleMigrated();
});
diff --git a/src/lib/auth.ts b/src/lib/auth.ts
index d5bce761c..0d05b63b4 100644
--- a/src/lib/auth.ts
+++ b/src/lib/auth.ts
@@ -1,7 +1,6 @@
import { createAuthClient } from "better-auth/react";
import { OPENWHISPR_API_URL } from "../config/constants";
import { openExternalLink } from "../utils/externalLinks";
-import logger from "../utils/logger";
export const AUTH_URL = import.meta.env.VITE_AUTH_URL || "https://auth.openwhispr.com";
export const authClient = createAuthClient({
@@ -161,57 +160,21 @@ export async function withSessionRefresh<T>(operation: () => Promise<T>): Promis
}
}
-function getElectronOAuthCallbackURL(): string {
- const configuredUrl = (import.meta.env.VITE_OPENWHISPR_OAUTH_CALLBACK_URL || "").trim();
- if (configuredUrl) return configuredUrl;
-
- if (window.location.protocol !== "file:") return `${window.location.origin}/?panel=true`;
-
- const port = import.meta.env.VITE_DEV_SERVER_PORT || "5183";
- return `http://localhost:${port}/?panel=true`;
-}
+const DESKTOP_OAUTH_CALLBACK_URL = "https://openwhispr.com/auth/desktop-callback";
export async function signInWithSocial(provider: SocialProvider): Promise<{ error?: Error }> {
- // State enforced server-side by Better Auth.
try {
const isElectron = Boolean((window as any).electronAPI);
if (isElectron) {
- const callbackURL = getElectronOAuthCallbackURL();
-
- const response = await fetch(`${AUTH_URL}/api/auth/sign-in/social`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "x-openwhispr-source": "desktop",
- },
- credentials: "include",
- body: JSON.stringify({
- provider,
- callbackURL,
- newUserCallbackURL: callbackURL,
- disableRedirect: true,
- }),
- });
-
- const text = await response.text();
-
- if (!response.ok) {
- logger.error(`Social sign-in failed: ${response.status}`, text.slice(0, 200), "auth");
- return { error: new Error("Failed to initiate sign-in") };
- }
-
- let data: { url?: string };
- try {
- data = JSON.parse(text);
- } catch {
- logger.error("Non-JSON response from auth server", text.slice(0, 200), "auth");
- return { error: new Error("Unexpected response from auth server") };
- }
-
- if (!data.url) return { error: new Error("Failed to get OAuth URL") };
-
- openExternalLink(data.url);
+ // OAuth must be initiated from the user's browser, not the renderer:
+ // the state cookie Better Auth sets has to land in the same cookie jar
+ // that handles the /api/auth/callback/* round-trip. The shim endpoint
+ // does the POST server-side and 302s with the cookies attached.
+ const protocol = (await window.electronAPI?.getOAuthProtocol?.()) || "openwhispr";
+ const url = new URL(`${AUTH_URL}/api/desktop-signin/${provider}`);
+ url.searchParams.set("callbackURL", `${DESKTOP_OAUTH_CALLBACK_URL}?protocol=${protocol}`);
+ openExternalLink(url.toString());
return {};
}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index ac8e15c75..61c0c23f9 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -772,6 +772,7 @@ declare global {
getAppVersion: () => Promise<AppVersionResult>;
getPostMigrationState: () => Promise<{ justMigrated: boolean }>;
getOAuthProtocolRegistered: () => Promise<boolean>;
+ getOAuthProtocol: () => Promise<string>;
markBundleMigrated: () => Promise<void>;
markBundleMigrationDismissed: () => Promise<void>;
getUpdateStatus: () => Promise<UpdateStatusResult>;