From 726a579c3b210e4b5bac9d79856aefdaf2c92368 Mon Sep 17 00:00:00 2001 From: emrah Date: Sat, 12 Oct 2024 14:44:20 +0300 Subject: [PATCH] fix: set sub and room in token --- adapter.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/adapter.ts b/adapter.ts index ae0daa5..adc0dcc 100644 --- a/adapter.ts +++ b/adapter.ts @@ -59,6 +59,8 @@ function unauthorized(): Response { // ----------------------------------------------------------------------------- async function generateJWT( userInfo: Record, + sub: string, + room: string, ): Promise { try { const encoder = new TextEncoder(); @@ -79,8 +81,8 @@ async function generateJWT( const payload = { aud: JWT_APP_ID, iss: JWT_APP_ID, - sub: "*", - room: "*", + sub: sub, + room: room, iat: getNumericDate(0), nbf: getNumericDate(0), exp: getNumericDate(JWT_EXP_SECOND), @@ -188,6 +190,8 @@ async function tokenize(req: Request): Promise { const path = qs.get("path") || ""; const search = qs.get("search") || ""; const hash = qs.get("hash") || ""; + const room = path.split("/").reverse()[0]; + const tenant = path.split("/").reverse()[1]?.toLowerCase(); if (DEBUG) console.log(`tokenize code: ${code}`); @@ -209,7 +213,7 @@ async function tokenize(req: Request): Promise { if (!userInfo) return unauthorized(); // generate JWT - const jwt = await generateJWT(userInfo); + const jwt = await generateJWT(userInfo, tenant || host, room); if (DEBUG) console.log(`tokenize token: ${jwt}`);