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
+14 -6
View File
@@ -17,11 +17,13 @@ import {
LocalStorageCryptoStore,
RoomNameType,
type RoomNameState,
type TokenRefreshFunction,
EventTimelineSet,
EventTimeline,
type OAuth2,
TokenRefresher,
} from "matrix-js-sdk/src/matrix";
import { VerificationMethod } from "matrix-js-sdk/src/types";
import { logger } from "matrix-js-sdk/src/logger";
import indexeddbWorkerFactory from "../workers/indexeddbWorkerFactory";
import SettingsStore from "../settings/SettingsStore";
@@ -29,6 +31,7 @@ import { crossSigningCallbacks } from "../SecurityManager";
import IdentityAuthClient from "../IdentityAuthClient";
import { _t } from "../languageHandler";
import { formatList } from "./FormattingUtils";
import { persistTokens } from "./tokens/tokens.ts";
const localStorage = window.localStorage;
@@ -116,14 +119,19 @@ function roomNameGenerator(_: string, state: RoomNameState): string | null {
* Create a new matrix client from credentials with all the options needed.
*
* @param creds The credentials to create the client with
* @param tokenRefreshFunction Optional function to call when the access token is expired
* @param oauth The OAuth2 instance for OAuth2-native sessions
*
* @returns {MatrixClient} the newly-created MatrixClient
*/
export function createClientWithCreds(
creds: IMatrixClientCreds,
tokenRefreshFunction?: TokenRefreshFunction,
): MatrixClient {
export function createClientWithCreds(creds: IMatrixClientCreds, oauth?: OAuth2): MatrixClient {
let tokenRefreshFunction: ICreateClientOpts["tokenRefreshFunction"];
if (creds.refreshToken && oauth) {
const tokenRefresher = new TokenRefresher(oauth, persistTokens.bind(null, creds.pickleKey));
tokenRefreshFunction = tokenRefresher?.tokenRefreshFunction;
} else {
logger.debug("No refresh token was supplied: access token will not be refreshed");
}
const opts: ICreateClientOpts = {
baseUrl: creds.homeserverUrl,
idBaseUrl: creds.identityServerUrl,