Adapt OAuth2 implementation to Matrix Spec v1.18 (#34026)

* Adapt OAuth2 implementation to Matrix Spec v1.18

* Handle more cases of oidc->oauth

* Fix test

* Fix read back of oauth2 context

* Iterate

* Fix tests

* Discard changes to apps/web/playwright/e2e/settings/account-user-settings-tab.spec.ts

* Fix test

* Fix test

* Fix test

* Potential fix for pull request finding 'Unused variable, import, function or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Iterate

* Iterate

* Fix test

---------

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This commit is contained in:
Michael Telatynski
2026-07-08 09:02:25 +01:00
committed by GitHub
parent 38e29c51c4
commit 2bc9656957
69 changed files with 761 additions and 1738 deletions
@@ -86,7 +86,7 @@ describe("ElectronPlatform", () => {
it("should return oidc client state as expected", async () => {
const platform = new ElectronPlatform();
await platform.getConfig();
expect(platform.getOidcClientState()).toMatchInlineSnapshot(`":element-desktop-ssoid:session-id"`);
expect(platform.getOAuthClientState()).toMatchInlineSnapshot(`":element-desktop-ssoid:session-id"`);
});
it("dispatches view settings action on preferences event", () => {
@@ -14,7 +14,7 @@ import {
type MatrixClient,
type Room,
type MatrixEvent,
type OidcRegistrationClientMetadata,
type OAuthRegistrationRequest,
} from "matrix-js-sdk/src/matrix";
import React from "react";
import { logger } from "matrix-js-sdk/src/logger";
@@ -531,28 +531,28 @@ export default class ElectronPlatform extends BasePlatform {
return (SdkConfig.get() as unknown as Record<string, string>)["web_base_url"] ?? "https://app.element.io";
}
public get defaultOidcClientUri(): string {
public get defaultOAuthClientUri(): string {
// Default to element.io as our scheme `io.element.desktop` is within its scope on default MAS policies
return "https://element.io";
}
public async getOidcClientMetadata(): Promise<OidcRegistrationClientMetadata> {
const baseMetadata = await super.getOidcClientMetadata();
public async getOAuthClientMetadata(): Promise<OAuthRegistrationRequest> {
const baseMetadata = await super.getOAuthClientMetadata();
return {
...baseMetadata,
applicationType: "native",
application_type: "native",
};
}
public getOidcClientState(): string {
public getOAuthClientState(): string {
return `:${SSO_ID_KEY}:${this.sessionId}`;
}
/**
* The URL to return to after a successful OIDC authentication
*/
public getOidcCallbackUrl(): URL {
const url = super.getOidcCallbackUrl();
public getOAuthCallbackUrl(): URL {
const url = super.getOAuthCallbackUrl();
url.protocol = this.protocol;
// Trim the double slash into a single slash to comply with https://datatracker.ietf.org/doc/html/rfc8252#section-7.1
if (url.href.startsWith(`${url.protocol}//`)) {
@@ -269,7 +269,7 @@ describe("WebPlatform", () => {
expect(spy).toHaveBeenCalledWith(expect.anything(), { bgColor: "#f00" });
});
describe("getOidcCallbackUrl()", () => {
describe("getOAuthCallbackUrl()", () => {
it("should not include the 'updated' query param in the redirect URI", () => {
Object.defineProperty(window, "location", {
value: {
@@ -280,7 +280,7 @@ describe("WebPlatform", () => {
writable: true,
});
const platform = new WebPlatform();
const url = platform.getOidcCallbackUrl();
const url = platform.getOAuthCallbackUrl();
expect(url.searchParams.has("updated")).toBe(false);
expect(url.searchParams.get("no_universal_links")).toEqual("true");