Skip to content

Commit

Permalink
add yolo-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Jul 19, 2024
1 parent a5a7889 commit 9a6825e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,56 @@ function auth(req: Request): Response {
return oidcRedirectForCode(req, "login");
}

function generateGUID() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
}

function yolo_auth(req: Request): Response {
// Don't go to keycloak if the room name is prefixed yolo_ and just create a usable JWT
const host = req.headers.get("host");
const url = new URL(req.url);
const qs = new URLSearchParams(url.search);
const path = qs.get("path");
const search = qs.get("search") || "";
const hash = qs.get("hash") || "";

console.log("Got a yolo requerst for " + path)

// check if it's really a yolo
if (!path.startsWith("yolo_")) {
console.log("Not yolo. aborting.")
return new Response("no-yolo", {
status: STATUS_CODE.FORBIDDEN,
});
}

// Generate JWT
const userInfo = {
"id": generateGUID(),
//"name": "Fellow Jitster",
//"email": "[email protected]",
"lobby_bypass": true,
"security_bypass": true,
"affiliation": "owner"
}
let roomName = path.slice(1);
const jwt = await generateJWT(userInfo, roomName);

if (DEBUG) console.log(`tokenize token: ${jwt}`);

const redirectUrl = path + '?oidc=authenticated&jwt=' + JSON.stringify(jwt);

// Create a Response object with a 302 redirect status
return new Response(null, {
status: 302,
headers: {
'Location': redirectUrl
}
});
}
// -----------------------------------------------------------------------------
// handler
// -----------------------------------------------------------------------------
Expand All @@ -342,6 +392,8 @@ async function handler(req: Request): Promise<Response> {
return ok("healthy");
} else if (path === "/oidc/health") {
return ok("healthy");
} else if (path === "/oidc/yolo") {
return yolo_auth(req);
} else if (path === "/oidc/redirect") {
return redirect(req);
} else if (path === "/oidc/tokenize") {
Expand Down

0 comments on commit 9a6825e

Please sign in to comment.