Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for io.element.desktop scheme for OIDC #1662

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions electron-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));

interface Configuration extends BaseConfiguration {
extraMetadata: Partial<Pick<Pkg, "version">> & Omit<Pkg, "version">;
linux: {
desktop: Record<string, string>;
} & BaseConfiguration["linux"];
linux: BaseConfiguration["linux"];
win: BaseConfiguration["win"];
mac: BaseConfiguration["mac"];
deb: {
Expand Down Expand Up @@ -118,9 +116,6 @@ const config: Writable<Configuration> = {
category: "Network;InstantMessaging;Chat",
maintainer: "support@element.io",
icon: "build/icons",
desktop: {
MimeType: "x-scheme-handler/element",
},
Comment on lines -121 to -123
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as electron-builder now correctly specifies it from the protocol definition lower down

},
deb: {
packageCategory: "net",
Expand Down Expand Up @@ -167,7 +162,7 @@ const config: Writable<Configuration> = {
protocols: [
{
name: "element",
schemes: ["element"],
schemes: ["io.element.desktop", "element"],
},
],
};
Expand Down
17 changes: 10 additions & 7 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { URL } from "url";
import path from "path";
import fs from "fs";

const PROTOCOL = "element:";
const LEGACY_PROTOCOL = "element";
const PROTOCOL = "io.element.desktop";
const SEARCH_PARAM = "element-desktop-ssoid";
const STORE_FILE_NAME = "sso-sessions.json";

Expand All @@ -33,7 +34,7 @@ function processUrl(url: string): void {
// sanity check: we only register for the one protocol, so we shouldn't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only register for the one protocol

This appears to be incorrect, ftr...

// be getting anything else unless the user is forcing a URL to open
// with the Element app.
if (parsed.protocol !== PROTOCOL) {
if (parsed.protocol !== `${PROTOCOL}:` && parsed.protocol !== `${LEGACY_PROTOCOL}:`) {
console.log("Ignoring unexpected protocol: ", parsed.protocol);
return;
}
Expand Down Expand Up @@ -82,10 +83,10 @@ export function recordSSOSession(sessionID: string): void {

export function getProfileFromDeeplink(args: string[]): string | undefined {
// check if we are passed a profile in the SSO callback url
const deeplinkUrl = args.find((arg) => arg.startsWith(PROTOCOL + "//"));
const deeplinkUrl = args.find((arg) => arg.startsWith(`${PROTOCOL}://`) || arg.startsWith(`${LEGACY_PROTOCOL}://`));
if (deeplinkUrl?.includes(SEARCH_PARAM)) {
const parsedUrl = new URL(deeplinkUrl);
if (parsedUrl.protocol === PROTOCOL) {
if (parsedUrl.protocol === `${PROTOCOL}:` || parsedUrl.protocol === `${LEGACY_PROTOCOL}:`) {
const store = readStore();
let ssoID = parsedUrl.searchParams.get(SEARCH_PARAM);
if (!ssoID) {
Expand All @@ -105,11 +106,13 @@ export function protocolInit(): void {
// --profile/--profile-dir are passed via the SEARCH_PARAM var in the callback url
const args = process.argv.slice(1).filter((arg) => arg !== "--hidden" && arg !== "-hidden");
if (app.isPackaged) {
app.setAsDefaultProtocolClient("element", process.execPath, args);
app.setAsDefaultProtocolClient(PROTOCOL, process.execPath, args);
app.setAsDefaultProtocolClient(LEGACY_PROTOCOL, process.execPath, args);
} else if (process.platform === "win32") {
// on Mac/Linux this would just cause the electron binary to open
// special handler for running without being packaged, e.g `electron .` by passing our app path to electron
app.setAsDefaultProtocolClient("element", process.execPath, [app.getAppPath(), ...args]);
app.setAsDefaultProtocolClient(PROTOCOL, process.execPath, [app.getAppPath(), ...args]);
app.setAsDefaultProtocolClient(LEGACY_PROTOCOL, process.execPath, [app.getAppPath(), ...args]);
}

if (process.platform === "darwin") {
Expand All @@ -122,7 +125,7 @@ export function protocolInit(): void {
// Protocol handler for win32/Linux
app.on("second-instance", (ev, commandLine) => {
const url = commandLine[commandLine.length - 1];
if (!url.startsWith(PROTOCOL + "//")) return;
if (!url.startsWith(`${PROTOCOL}://`) && !url.startsWith(`${LEGACY_PROTOCOL}://`)) return;
processUrl(url);
});
}
Expand Down
Loading