@@ -19,6 +19,7 @@ require("./index.scss");
1919
2020import * as qs from 'querystring' ;
2121import { 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;
3334let displayName : string ;
3435let avatarUrl : string ;
3536let userId : string ;
37+ let jitsiAuth : string ;
38+ let roomId : string ;
3639
3740let 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+
94138function 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 ) ;
0 commit comments