Skip to content

Commit 5108697

Browse files
committed
Add support for Jitsi openidtoken-jwt auth
If the widget URL specifies this auth, generate a JWT token containing the info needed by the Jitsi backend.
1 parent e5a4092 commit 5108697

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"browser-request": "^0.3.3",
6060
"gfm.css": "^1.1.2",
6161
"highlight.js": "^9.13.1",
62+
"jsrsasign": "^9.1.5",
6263
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop",
6364
"matrix-react-sdk": "github:matrix-org/matrix-react-sdk#develop",
6465
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",

src/vector/jitsi/index.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require("./index.scss");
1919

2020
import * as qs from 'querystring';
2121
import { Capability, WidgetApi } from "matrix-react-sdk/src/widgets/WidgetApi";
22+
import { KJUR } from "jsrsasign";
2223

2324
// Dev note: we use raw JS without many dependencies to reduce bundle size.
2425
// We do not need all of React to render a Jitsi conference.
@@ -33,6 +34,8 @@ let conferenceId: string;
3334
let displayName: string;
3435
let avatarUrl: string;
3536
let userId: string;
37+
let jitsiAuth: string;
38+
let roomId: string;
3639

3740
let widgetApi: WidgetApi;
3841

@@ -69,6 +72,8 @@ let widgetApi: WidgetApi;
6972
displayName = qsParam('displayName', true);
7073
avatarUrl = qsParam('avatarUrl', true); // http not mxc
7174
userId = qsParam('userId');
75+
jitsiAuth = qsParam('auth', true);
76+
roomId = qsParam('roomId', true);
7277

7378
if (widgetApi) {
7479
await widgetApi.waitReady();
@@ -91,6 +96,45 @@ function switchVisibleContainers() {
9196
document.getElementById("joinButtonContainer").style.visibility = inConference ? 'hidden' : 'unset';
9297
}
9398

99+
/**
100+
* Create a JWT token fot jitsi openidtoken-jwt auth
101+
*
102+
* See TODO add link
103+
*/
104+
function createJWTToken() {
105+
// Header
106+
const header = {alg: 'HS256', typ: 'JWT'};
107+
// Payload
108+
const payload = {
109+
// TODO change this to refer to spec?
110+
iss: "app_id",
111+
sub: jitsiDomain,
112+
aud: `https://${jitsiDomain}`,
113+
room: "*",
114+
context: {
115+
matrix: {
116+
// TODO openid token retrieved as per MSC1960
117+
token: "foobar",
118+
room_id: roomId,
119+
},
120+
user: {
121+
avatar: avatarUrl,
122+
name: displayName,
123+
},
124+
},
125+
};
126+
// Sign JWT
127+
// The secret string here is irrelevant, we're only using the JWT
128+
// to transport data to Prosody in the Jitsi stack.
129+
// See TODO add link
130+
return KJUR.jws.JWS.sign(
131+
"HS256",
132+
JSON.stringify(header),
133+
JSON.stringify(payload),
134+
"notused",
135+
);
136+
}
137+
94138
function joinConference() { // event handler bound in HTML
95139
switchVisibleContainers();
96140

@@ -102,7 +146,7 @@ function joinConference() { // event handler bound in HTML
102146
"they mention 'external_api' or 'jitsi' in the stack. They're just Jitsi Meet trying to parse " +
103147
"our fragment values and not recognizing the options.",
104148
);
105-
const meetApi = new JitsiMeetExternalAPI(jitsiDomain, {
149+
const options = {
106150
width: "100%",
107151
height: "100%",
108152
parentNode: document.querySelector("#jitsiContainer"),
@@ -113,7 +157,12 @@ function joinConference() { // event handler bound in HTML
113157
MAIN_TOOLBAR_BUTTONS: [],
114158
VIDEO_LAYOUT_FIT: "height",
115159
},
116-
});
160+
jwt: undefined,
161+
};
162+
if (jitsiAuth === "openidtoken-jwt") {
163+
options.jwt = createJWTToken();
164+
}
165+
const meetApi = new JitsiMeetExternalAPI(jitsiDomain, options);
117166
if (displayName) meetApi.executeCommand("displayName", displayName);
118167
if (avatarUrl) meetApi.executeCommand("avatarUrl", avatarUrl);
119168
if (userId) meetApi.executeCommand("email", userId);

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6914,6 +6914,11 @@ jsprim@^1.2.2:
69146914
json-schema "0.2.3"
69156915
verror "1.10.0"
69166916

6917+
jsrsasign@^9.1.5:
6918+
version "9.1.5"
6919+
resolved "https://registry.yarnpkg.com/jsrsasign/-/jsrsasign-9.1.5.tgz#fe286425d2c05b2d0865d24ded53e34b12abd2ca"
6920+
integrity sha512-iJLF8FvZHlwyQudrRtQomHj1HdPAcM8QSRTt0FJo8a6iFgaGCpKUrE7lWyELpAjrFs8jUC/Azc0vfhlj3yqHPQ==
6921+
69176922
jsx-ast-utils@^2.2.3:
69186923
version "2.3.0"
69196924
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.3.0.tgz#edd727794ea284d7fda575015ed1b0cde0289ab6"

0 commit comments

Comments
 (0)