From c19737b387ebd0ba35746bc9731f27b47df44fd8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 15 Feb 2024 17:03:19 +0000 Subject: [PATCH 1/2] Improve client metadata used for OIDC dynamic registration Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index c096bdc7d3..8fb45f85dc 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -43,6 +43,7 @@ import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore"; import { UPDATE_EVENT } from "matrix-react-sdk/src/stores/AsyncStore"; import { avatarUrlForRoom, getInitialLetter } from "matrix-react-sdk/src/Avatar"; import DesktopCapturerSourcePicker from "matrix-react-sdk/src/components/views/elements/DesktopCapturerSourcePicker"; +import { OidcRegistrationClientMetadata } from "matrix-js-sdk/src/matrix"; import VectorBasePlatform from "./VectorBasePlatform"; import { SeshatIndexManager } from "./SeshatIndexManager"; @@ -435,4 +436,19 @@ export default class ElectronPlatform extends VectorBasePlatform { await this.ipc.call("clearStorage"); } catch (e) {} } + + public get baseUrl(): string { + // This configuration is element-desktop specific so the types here do not know about it + return (SdkConfig.get() as unknown as Record)["web_base_url"] ?? "https://app.element.io"; + } + + public async getOidcClientMetadata(): Promise { + const baseMetadata = await super.getOidcClientMetadata(); + return { + ...baseMetadata, + applicationType: "native", + // XXX: This should be overridable in config + clientUri: "https://element.io", + }; + } } From aa5024adae13d856764f1c7af87340f336b92374 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 15 Feb 2024 17:36:27 +0000 Subject: [PATCH 2/2] Fix Native OIDC for Element Desktop by including ssoid in the url_state of the /auth call Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 8fb45f85dc..fa776c4ccb 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -57,6 +57,8 @@ interface SquirrelUpdate { updateURL: string; } +const SSO_ID_KEY = "element-desktop-ssoid"; + const isMac = navigator.platform.toUpperCase().includes("MAC"); function platformFriendlyName(): string { @@ -378,7 +380,7 @@ export default class ElectronPlatform extends VectorBasePlatform { public getSSOCallbackUrl(fragmentAfterLogin: string): URL { const url = super.getSSOCallbackUrl(fragmentAfterLogin); url.protocol = "element"; - url.searchParams.set("element-desktop-ssoid", this.ssoID); + url.searchParams.set(SSO_ID_KEY, this.ssoID); return url; } @@ -451,4 +453,8 @@ export default class ElectronPlatform extends VectorBasePlatform { clientUri: "https://element.io", }; } + + public getOidcClientState(): string { + return `:${SSO_ID_KEY}:${this.ssoID}`; + } }