@@ -17,7 +17,8 @@ import {
17
17
KEYCLOAK_ORIGIN_INTERNAL ,
18
18
KEYCLOAK_REALM ,
19
19
PORT ,
20
- PERMISSIONS_FILE
20
+ PERMISSIONS_FILE ,
21
+ ALLOWED_DOMAINS
21
22
} from "./config.ts" ;
22
23
import { createContext } from "./context.ts" ;
23
24
@@ -98,6 +99,17 @@ async function generateJWT(
98
99
}
99
100
}
100
101
102
+ // -----------------------------------------------------------------------------
103
+ // Check if the domain is allowed to moderate the room
104
+ // -----------------------------------------------------------------------------
105
+ function isAllowedDomain ( email : string , allowedDomains : string [ ] ) : boolean {
106
+ if ( ! allowedDomains . length ) return true ; // If no domains specified, allow all
107
+ if ( ! email ) return false ;
108
+
109
+ const domain = email . split ( "@" ) [ 1 ] ?. toLowerCase ( ) ;
110
+ return allowedDomains . some ( allowed => allowed . toLowerCase ( ) === domain ) ;
111
+ }
112
+
101
113
// -----------------------------------------------------------------------------
102
114
// Get the access token from Keycloak by using the short-term auth code
103
115
//
@@ -213,6 +225,12 @@ async function tokenize(req: Request): Promise<Response> {
213
225
const userInfo = await getUserInfo ( token ) ;
214
226
if ( ! userInfo ) return unauthorized ( ) ;
215
227
228
+ // Check email domain
229
+ if ( ! isAllowedDomain ( userInfo [ "email" ] as string , ALLOWED_DOMAINS ) ) {
230
+ console . log ( `User ${ userInfo [ "email" ] } is not allowed to access the room` ) ;
231
+ return unauthorized ( ) ;
232
+ }
233
+
216
234
// Enhance userinfo
217
235
userInfo [ "lobby_bypass" ] = true ;
218
236
userInfo [ "security_bypass" ] = true ;
@@ -469,6 +487,7 @@ function main() {
469
487
if ( PERMISSIONS_FILE ) {
470
488
console . log ( `PERMISSIONS_FILE: ${ PERMISSIONS_FILE } ` ) ;
471
489
}
490
+ console . log ( `ALLOWED_DOMAINS: ${ ALLOWED_DOMAINS } ` ) ;
472
491
473
492
serve ( handler , {
474
493
hostname : HOSTNAME ,
0 commit comments