From 9de5f0172719bade1c1024ca7ce6cdb5d897ea61 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 11 Jun 2024 11:33:48 +0530 Subject: [PATCH] Add protocol --- desktop/electron-builder.yml | 3 +++ desktop/src/main.ts | 17 ++++++++++++++++ web/packages/accounts/services/passkey.ts | 24 +++++++++++------------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/desktop/electron-builder.yml b/desktop/electron-builder.yml index 347aabe631..6e3df57656 100644 --- a/desktop/electron-builder.yml +++ b/desktop/electron-builder.yml @@ -6,6 +6,9 @@ files: extraFiles: - from: build to: resources +protocols: + - name: Ente + schemes: ["ente"] win: target: - target: nsis diff --git a/desktop/src/main.ts b/desktop/src/main.ts index afbf4eccd3..c795e938c2 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -137,6 +137,22 @@ const registerPrivilegedSchemes = () => { ]); }; +/** + * Register a handler for deeplinks, for the "ente://" protocol. + * + * See: [Note: Passkey verification in the desktop app]. + * + * Implementation notes: + * - https://www.electronjs.org/docs/latest/tutorial/launch-app-from-url-in-another-app + * - This works only when the app is packaged. + */ +const handleEnteLinks = () => { + app.setAsDefaultProtocolClient("ente"); + app.on("open-url", (_, url) => { + log.info(`open-url: ${url}`); + }); +}; + /** * Create an return the {@link BrowserWindow} that will form our app's UI. * @@ -451,6 +467,7 @@ const main = () => { initLogging(); logStartupBanner(); + handleEnteLinks(); // The order of the next two calls is important setupRendererServer(); registerPrivilegedSchemes(); diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts index ae455638a0..793464f6b9 100644 --- a/web/packages/accounts/services/passkey.ts +++ b/web/packages/accounts/services/passkey.ts @@ -29,13 +29,6 @@ export const redirectUserToPasskeyVerificationFlow = ( passkeySessionID: string, ) => { const clientPackage = clientPackageName[appName]; - const redirect = `${window.location.origin}/passkeys/finish`; - const params = new URLSearchParams({ - clientPackage, - passkeySessionID, - redirect, - }); - const url = `${accountsAppURL()}/passkeys/verify?${params.toString()}`; // [Note: Passkey verification in the desktop app] // // Our desktop app bundles the web app and serves it over a custom protocol. @@ -54,11 +47,18 @@ export const redirectUserToPasskeyVerificationFlow = ( // protocol and provide that as a return path redirect. Passkey // authentication happens at accounts.ente.io, and on success there is // redirected back to the desktop app. - if (globalThis.electron) { - window.open(url); - } else { - window.location.href = url; - } + const redirectOrigin = globalThis.electron + ? "ente://" + : window.location.origin; + const redirect = `${redirectOrigin}/passkeys/finish`; + const params = new URLSearchParams({ + clientPackage, + passkeySessionID, + redirect, + }); + const url = `${accountsAppURL()}/passkeys/verify?${params.toString()}`; + if (globalThis.electron) window.open(url); + else window.location.href = url; }; /**