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;
}
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<OidcRegistrationClientMetadata> {
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;
}
}