From 9efa04da7a4865842bc14cd94aa56bee6dc53004 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 May 2024 11:58:58 +0100 Subject: [PATCH] Split out oidc callback url into its own method Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 0ae1f75863..dddf73ae07 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -57,6 +57,8 @@ interface SquirrelUpdate { updateURL: string; } +const LEGACY_PROTOCOL = "element"; +const OIDC_PROTOCOL = "io.element.desktop"; const SSO_ID_KEY = "element-desktop-ssoid"; const isMac = navigator.platform.toUpperCase().includes("MAC"); @@ -377,12 +379,10 @@ export default class ElectronPlatform extends VectorBasePlatform { return this.ipc.call("getAvailableSpellCheckLanguages"); } - public getSSOCallbackUrl(forOidc = false, fragmentAfterLogin?: string): URL { - const url = super.getSSOCallbackUrl(forOidc, fragmentAfterLogin); - url.protocol = "element"; - if (!forOidc) { - url.searchParams.set(SSO_ID_KEY, this.ssoID); - } + public getSSOCallbackUrl(fragmentAfterLogin?: string): URL { + const url = super.getSSOCallbackUrl(fragmentAfterLogin); + url.protocol = LEGACY_PROTOCOL; + url.searchParams.set(SSO_ID_KEY, this.ssoID); return url; } @@ -448,11 +448,9 @@ export default class ElectronPlatform extends VectorBasePlatform { public async getOidcClientMetadata(): Promise { const baseMetadata = await super.getOidcClientMetadata(); - const redirectUri = this.getSSOCallbackUrl(true); return { ...baseMetadata, applicationType: "native", - redirectUris: [redirectUri.href], // XXX: This should be overridable in config clientUri: "https://element.io", }; @@ -461,4 +459,13 @@ export default class ElectronPlatform extends VectorBasePlatform { public getOidcClientState(): string { return `:${SSO_ID_KEY}:${this.ssoID}`; } + + /** + * The URL to return to after a successful OIDC authentication + */ + public getOidcCallbackUrl(): URL { + const url = super.getOidcCallbackUrl(); + url.protocol = OIDC_PROTOCOL; + return url; + } }