@@ -19,6 +19,7 @@ require("./index.scss");
19
19
20
20
import * as qs from 'querystring' ;
21
21
import { Capability , WidgetApi } from "matrix-react-sdk/src/widgets/WidgetApi" ;
22
+ import { KJUR } from "jsrsasign" ;
22
23
23
24
// Dev note: we use raw JS without many dependencies to reduce bundle size.
24
25
// We do not need all of React to render a Jitsi conference.
@@ -33,6 +34,8 @@ let conferenceId: string;
33
34
let displayName : string ;
34
35
let avatarUrl : string ;
35
36
let userId : string ;
37
+ let jitsiAuth : string ;
38
+ let roomId : string ;
36
39
37
40
let widgetApi : WidgetApi ;
38
41
@@ -69,6 +72,8 @@ let widgetApi: WidgetApi;
69
72
displayName = qsParam ( 'displayName' , true ) ;
70
73
avatarUrl = qsParam ( 'avatarUrl' , true ) ; // http not mxc
71
74
userId = qsParam ( 'userId' ) ;
75
+ jitsiAuth = qsParam ( 'auth' , true ) ;
76
+ roomId = qsParam ( 'roomId' , true ) ;
72
77
73
78
if ( widgetApi ) {
74
79
await widgetApi . waitReady ( ) ;
@@ -91,6 +96,45 @@ function switchVisibleContainers() {
91
96
document . getElementById ( "joinButtonContainer" ) . style . visibility = inConference ? 'hidden' : 'unset' ;
92
97
}
93
98
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
+
94
138
function joinConference ( ) { // event handler bound in HTML
95
139
switchVisibleContainers ( ) ;
96
140
@@ -102,7 +146,7 @@ function joinConference() { // event handler bound in HTML
102
146
"they mention 'external_api' or 'jitsi' in the stack. They're just Jitsi Meet trying to parse " +
103
147
"our fragment values and not recognizing the options." ,
104
148
) ;
105
- const meetApi = new JitsiMeetExternalAPI ( jitsiDomain , {
149
+ const options = {
106
150
width : "100%" ,
107
151
height : "100%" ,
108
152
parentNode : document . querySelector ( "#jitsiContainer" ) ,
@@ -113,7 +157,12 @@ function joinConference() { // event handler bound in HTML
113
157
MAIN_TOOLBAR_BUTTONS : [ ] ,
114
158
VIDEO_LAYOUT_FIT : "height" ,
115
159
} ,
116
- } ) ;
160
+ jwt : undefined ,
161
+ } ;
162
+ if ( jitsiAuth === "openidtoken-jwt" ) {
163
+ options . jwt = createJWTToken ( ) ;
164
+ }
165
+ const meetApi = new JitsiMeetExternalAPI ( jitsiDomain , options ) ;
117
166
if ( displayName ) meetApi . executeCommand ( "displayName" , displayName ) ;
118
167
if ( avatarUrl ) meetApi . executeCommand ( "avatarUrl" , avatarUrl ) ;
119
168
if ( userId ) meetApi . executeCommand ( "email" , userId ) ;
0 commit comments