Merge branch 't3chguy/fix-oidc-native-electron' of https://github.com/vector-im/element-web into develop

This commit is contained in:
Michael Telatynski 2024-05-10 12:58:58 +01:00
commit 84b6bf9789
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");
@ -379,7 +381,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
public getSSOCallbackUrl(fragmentAfterLogin?: string): URL {
const url = super.getSSOCallbackUrl(fragmentAfterLogin);
url.protocol = "element";
url.protocol = LEGACY_PROTOCOL;
url.searchParams.set(SSO_ID_KEY, this.ssoID);
return url;
}
@ -446,12 +448,9 @@ export default class ElectronPlatform extends VectorBasePlatform {
public async getOidcClientMetadata(): Promise<OidcRegistrationClientMetadata> {
const baseMetadata = await super.getOidcClientMetadata();
const redirectUri = this.getSSOCallbackUrl();
redirectUri.searchParams.delete(SSO_ID_KEY); // it will be shuttled via the state param instead
return {
...baseMetadata,
applicationType: "native",
redirectUris: [redirectUri.href],
// XXX: This should be overridable in config
clientUri: "https://element.io",
};
@ -460,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;
}
}