This commit is contained in:
Warunee Tamkoo 2025-02-11 11:02:09 +07:00
parent 3c7b8e5484
commit 42184cb442

26
sso.js
View file

@ -85,7 +85,7 @@ app.post("/api/v1/sso/kcauth", async (req, res) => {
const clientSecret = process.env.KC_CLIENT_SECRET; const clientSecret = process.env.KC_CLIENT_SECRET;
const clientId = process.env.KC_CLIENT_ID; const clientId = process.env.KC_CLIENT_ID;
// const cookies = req.cookies; const cookies = req.cookies;
const uid = req.body.uid; const uid = req.body.uid;
// const tokenSSO = cookies[cookieName]; // const tokenSSO = cookies[cookieName];
@ -112,10 +112,10 @@ app.post("/api/v1/sso/kcauth", async (req, res) => {
const username = decrypted; const username = decrypted;
// } // }
const oldssotoken = cookies['oldssotoken']; // const oldssotoken = cookies['oldssotoken'];
const oldcid = cookies['oldcid']; const olduid = cookies['olduid'];
if (tokenSSO !== oldssotoken && username !== oldcid) { if (username !== olduid) {
// create body for admin token // create body for admin token
let body = { let body = {
client_id: clientId, client_id: clientId,
@ -160,13 +160,13 @@ app.post("/api/v1/sso/kcauth", async (req, res) => {
// console.log("==== user token ===="); // console.log("==== user token ====");
// console.log(tokenResponse.data); // console.log(tokenResponse.data);
// await postLog('เข้าสู่ระบบ', tokenResponse.data.access_token); // await postLog('เข้าสู่ระบบ', tokenResponse.data.access_token);
res.cookie('oldssotoken', tokenSSO, { // res.cookie('oldssotoken', tokenSSO, {
maxAge: 1000 * 60 * 60 * 24, // กำหนด timeout หน่วยเป็น millisecond // maxAge: 1000 * 60 * 60 * 24, // กำหนด timeout หน่วยเป็น millisecond
path: "/", // path: "/",
httpOnly: true, // httpOnly: true,
}); // });
res.cookie('oldcid', username, { res.cookie('olduid', username, {
maxAge: 1000 * 60 * 60 * 24, // กำหนด timeout หน่วยเป็น millisecond maxAge: 1000 * 60 * 60 * 24, // กำหนด timeout หน่วยเป็น millisecond
path: "/", path: "/",
httpOnly: true, httpOnly: true,
@ -184,11 +184,5 @@ app.post("/api/v1/sso/kcauth", async (req, res) => {
} }
}) })
// app.use(express.static(path.join(__dirname, "public-sso")));
// app.get("/", (_req, res) => {
// res.sendFile(`${process.cwd()}/sso.js`);
// });
console.log("Start BMA SSO Simulator at port " + port); console.log("Start BMA SSO Simulator at port " + port);
app.listen(port); app.listen(port);