From 69181b60e9945622f75b0f9d89c62072bfb2c6d1 Mon Sep 17 00:00:00 2001 From: emrah Date: Fri, 24 Feb 2023 16:32:03 +0300 Subject: [PATCH 1/3] Use a newly generated access_token while joining Jitsi --- src/vector/jitsi/index.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 4281b908f3e..e984c5e3755 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -212,13 +212,6 @@ const setupCompleted = (async (): Promise => { if (widgetApi) { await widgetApiReady; - - // See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification - if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) { - // Request credentials, give callback to continue when received - openIdToken = await widgetApi.requestOpenIDConnectToken(); - logger.log("Got OpenID Connect token"); - } } // Now that everything should be set up, skip to the Jitsi splash screen if needed @@ -234,7 +227,7 @@ const setupCompleted = (async (): Promise => { })(); function enableJoinButton(): void { - document.getElementById("joinButton").onclick = (): void => joinConference(); + document.getElementById("joinButton").onclick = (): Promise => joinConference(); } function switchVisibleContainers(): void { @@ -345,9 +338,13 @@ function mapLanguage(language: string): string { // audio input it can find, while an input of null instructs it to start muted, // and a non-nullish input specifies the label of a specific device to use. // Same for video inputs. -function joinConference(audioInput?: string | null, videoInput?: string | null): void { +async function joinConference(audioInput?: string | null, videoInput?: string | null): Promise { let jwt; if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) { + // Request credentials, give callback to continue when received + openIdToken = await widgetApi.requestOpenIDConnectToken(); + logger.log("Got OpenID Connect token"); + if (!openIdToken?.access_token) { // eslint-disable-line camelcase // We've failing to get a token, don't try to init conference From 0b39b99017b2a1b373bad08dcace1df9397c4928 Mon Sep 17 00:00:00 2001 From: emrah Date: Tue, 28 Feb 2023 14:07:45 +0300 Subject: [PATCH 2/3] openIdToken as a local variable in the Jitsi widget --- src/vector/jitsi/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index e984c5e3755..126e139d490 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -52,7 +52,6 @@ let avatarUrl: string; let userId: string; let jitsiAuth: string; let roomId: string; -let openIdToken: IOpenIDCredentials; let roomName: string; let startAudioOnly: boolean; let isVideoChannel: boolean; @@ -253,11 +252,11 @@ function skipToJitsiSplashScreen(): void { } /** - * Create a JWT token fot jitsi openidtoken-jwt auth + * Create a JWT token for jitsi openidtoken-jwt auth * * See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification */ -function createJWTToken(): string { +function createJWTToken(openIdToken: IOpenIDCredentials): string { // Header const header = { alg: "HS256", typ: "JWT" }; // Payload @@ -341,8 +340,8 @@ function mapLanguage(language: string): string { async function joinConference(audioInput?: string | null, videoInput?: string | null): Promise { let jwt; if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) { - // Request credentials, give callback to continue when received - openIdToken = await widgetApi.requestOpenIDConnectToken(); + // See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification + const openIdToken: IOpenIDCredentials = await widgetApi.requestOpenIDConnectToken(); logger.log("Got OpenID Connect token"); if (!openIdToken?.access_token) { @@ -352,7 +351,7 @@ async function joinConference(audioInput?: string | null, videoInput?: string | document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget"; return; } - jwt = createJWTToken(); + jwt = createJWTToken(openIdToken); } switchVisibleContainers(); From d2db8ee10db9d30b72355fd81d84052bd90fd7c5 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Wed, 22 Mar 2023 13:58:55 +0000 Subject: [PATCH 3/3] Update src/vector/jitsi/index.ts --- src/vector/jitsi/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 276008840c7..77379fe2097 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -355,7 +355,7 @@ async function joinConference(audioInput?: string | null, videoInput?: string | const openIdToken: IOpenIDCredentials = await widgetApi.requestOpenIDConnectToken(); logger.log("Got OpenID Connect token"); - if (!openIdToken?.access_token) { + if (!openIdToken.access_token) { // eslint-disable-line camelcase // We've failing to get a token, don't try to init conference logger.warn("Expected to have an OpenID credential, cannot initialize widget.");