Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cc69589

Browse files
t3chguyrichvdh
andauthored
Fix element-desktop-ssoid being included in OIDC Authorization call (#12495)
* Fix `element-desktop-ssoid being` included in OIDC Authorization call Signed-off-by: Michael Telatynski <[email protected]> * Split out oidc callback url into its own method Signed-off-by: Michael Telatynski <[email protected]> * Fix unexpected hash on oidc callback url Signed-off-by: Michael Telatynski <[email protected]> * Update src/BasePlatform.ts Co-authored-by: Richard van der Hoff <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]> Co-authored-by: Richard van der Hoff <[email protected]>
1 parent ed7a21a commit cc69589

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

src/BasePlatform.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export default abstract class BasePlatform {
315315
}
316316

317317
/**
318-
* The URL to return to after a successful SSO/OIDC authentication
318+
* The URL to return to after a successful SSO authentication
319319
* @param fragmentAfterLogin optional fragment for specific view to return to
320320
*/
321321
public getSSOCallbackUrl(fragmentAfterLogin = ""): URL {
@@ -438,7 +438,7 @@ export default abstract class BasePlatform {
438438
return {
439439
clientName: config.brand,
440440
clientUri: this.baseUrl,
441-
redirectUris: [this.getSSOCallbackUrl().href],
441+
redirectUris: [this.getOidcCallbackUrl().href],
442442
logoUri: new URL("vector-icons/1024.png", this.baseUrl).href,
443443
applicationType: "web",
444444
// XXX: We break the spec by not consistently supplying these required fields
@@ -457,4 +457,15 @@ export default abstract class BasePlatform {
457457
public getOidcClientState(): string {
458458
return "";
459459
}
460+
461+
/**
462+
* The URL to return to after a successful OIDC authentication
463+
*/
464+
public getOidcCallbackUrl(): URL {
465+
const url = new URL(window.location.href);
466+
// The redirect URL has to exactly match that registered at the OIDC server, so
467+
// ensure that the fragment part of the URL is empty.
468+
url.hash = "";
469+
return url;
470+
}
460471
}

src/Lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ async function createOidcTokenRefresher(credentials: IMatrixClientCreds): Promis
720720
try {
721721
const clientId = getStoredOidcClientId();
722722
const idTokenClaims = getStoredOidcIdTokenClaims();
723-
const redirectUri = PlatformPeg.get()!.getSSOCallbackUrl().href;
723+
const redirectUri = PlatformPeg.get()!.getOidcCallbackUrl().href;
724724
const deviceId = credentials.deviceId;
725725
if (!deviceId) {
726726
throw new Error("Expected deviceId in user credentials.");

src/stores/oidc/OidcClientStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class OidcClientStore {
169169
...metadata,
170170
authority: metadata.issuer,
171171
signingKeys,
172-
redirect_uri: PlatformPeg.get()!.getSSOCallbackUrl().href,
172+
redirect_uri: PlatformPeg.get()!.getOidcCallbackUrl().href,
173173
client_id: clientId,
174174
});
175175
} catch (error) {

src/utils/oidc/authorize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const startOidcLogin = async (
4040
identityServerUrl?: string,
4141
isRegistration?: boolean,
4242
): Promise<void> => {
43-
const redirectUri = PlatformPeg.get()!.getSSOCallbackUrl().href;
43+
const redirectUri = PlatformPeg.get()!.getOidcCallbackUrl().href;
4444

4545
const nonce = randomString(10);
4646

test/utils/oidc/registerClient-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("getOidcClientId()", () => {
4444
return baseUrl;
4545
},
4646
});
47-
Object.defineProperty(PlatformPeg.get(), "getSSOCallbackUrl", {
47+
Object.defineProperty(PlatformPeg.get(), "getOidcCallbackUrl", {
4848
value: () => ({
4949
href: baseUrl,
5050
}),

0 commit comments

Comments
 (0)