Skip to content

Commit

Permalink
fix: set sub and room in token
Browse files Browse the repository at this point in the history
  • Loading branch information
emrahcom committed Oct 12, 2024
1 parent 5247618 commit 726a579
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function unauthorized(): Response {
// -----------------------------------------------------------------------------
async function generateJWT(
userInfo: Record<string, unknown>,
sub: string,
room: string,
): Promise<string | undefined> {
try {
const encoder = new TextEncoder();
Expand All @@ -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),
Expand Down Expand Up @@ -188,6 +190,8 @@ async function tokenize(req: Request): Promise<Response> {
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}`);

Expand All @@ -209,7 +213,7 @@ async function tokenize(req: Request): Promise<Response> {
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}`);

Expand Down

0 comments on commit 726a579

Please sign in to comment.