Split out oidc callback url into its own method

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2024-05-10 11:58:58 +01:00
parent b82100ede8
commit 9efa04da7a
No known key found for this signature in database
GPG key ID: A2B008A5F49F5D0D

View file

@ -57,6 +57,8 @@ interface SquirrelUpdate {
updateURL: string; updateURL: string;
} }
const LEGACY_PROTOCOL = "element";
const OIDC_PROTOCOL = "io.element.desktop";
const SSO_ID_KEY = "element-desktop-ssoid"; const SSO_ID_KEY = "element-desktop-ssoid";
const isMac = navigator.platform.toUpperCase().includes("MAC"); const isMac = navigator.platform.toUpperCase().includes("MAC");
@ -377,12 +379,10 @@ export default class ElectronPlatform extends VectorBasePlatform {
return this.ipc.call("getAvailableSpellCheckLanguages"); return this.ipc.call("getAvailableSpellCheckLanguages");
} }
public getSSOCallbackUrl(forOidc = false, fragmentAfterLogin?: string): URL { public getSSOCallbackUrl(fragmentAfterLogin?: string): URL {
const url = super.getSSOCallbackUrl(forOidc, fragmentAfterLogin); const url = super.getSSOCallbackUrl(fragmentAfterLogin);
url.protocol = "element"; url.protocol = LEGACY_PROTOCOL;
if (!forOidc) { url.searchParams.set(SSO_ID_KEY, this.ssoID);
url.searchParams.set(SSO_ID_KEY, this.ssoID);
}
return url; return url;
} }
@ -448,11 +448,9 @@ export default class ElectronPlatform extends VectorBasePlatform {
public async getOidcClientMetadata(): Promise<OidcRegistrationClientMetadata> { public async getOidcClientMetadata(): Promise<OidcRegistrationClientMetadata> {
const baseMetadata = await super.getOidcClientMetadata(); const baseMetadata = await super.getOidcClientMetadata();
const redirectUri = this.getSSOCallbackUrl(true);
return { return {
...baseMetadata, ...baseMetadata,
applicationType: "native", applicationType: "native",
redirectUris: [redirectUri.href],
// XXX: This should be overridable in config // XXX: This should be overridable in config
clientUri: "https://element.io", clientUri: "https://element.io",
}; };
@ -461,4 +459,13 @@ export default class ElectronPlatform extends VectorBasePlatform {
public getOidcClientState(): string { public getOidcClientState(): string {
return `:${SSO_ID_KEY}:${this.ssoID}`; 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;
}
} }