updated
This commit is contained in:
parent
189e7fd51a
commit
3c7b8e5484
1 changed files with 23 additions and 24 deletions
39
sso.js
39
sso.js
|
|
@ -80,38 +80,37 @@ app.post("/api/v1/sso/signin", async (req, res) => {
|
||||||
app.post("/api/v1/sso/kcauth", async (req, res) => {
|
app.post("/api/v1/sso/kcauth", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// kcauth
|
// kcauth
|
||||||
const useBMA = Boolean(process.env.USE_BMA) || false;
|
// const useBMA = Boolean(process.env.USE_BMA) || false;
|
||||||
const publicKeyLanding = fs.readFileSync(`./BMA.pub.pem`, "utf8");
|
// const publicKeyLanding = fs.readFileSync(`./BMA.pub.pem`, "utf8");
|
||||||
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;
|
||||||
let uid = cookies["uid"];
|
const uid = req.body.uid;
|
||||||
|
|
||||||
let username = "";
|
// const tokenSSO = cookies[cookieName];
|
||||||
|
|
||||||
const tokenSSO = cookies[cookieName];
|
if (!uid) {
|
||||||
|
|
||||||
if (!tokenSSO && !uid) {
|
|
||||||
res.status(401).send("Unauthorized");
|
res.status(401).send("Unauthorized");
|
||||||
return;
|
return;
|
||||||
} else if (tokenSSO) {
|
|
||||||
let decodedToken = "";
|
|
||||||
if (useBMA) {
|
|
||||||
decodedToken = jwt.decode(tokenSSO);
|
|
||||||
} else {
|
|
||||||
decodedToken = jwt.verify(tokenSSO, publicKeyLanding);
|
|
||||||
}
|
}
|
||||||
|
// else if (tokenSSO) {
|
||||||
|
// let decodedToken = "";
|
||||||
|
// if (useBMA) {
|
||||||
|
// decodedToken = jwt.decode(tokenSSO);
|
||||||
|
// } else {
|
||||||
|
// decodedToken = jwt.verify(tokenSSO, publicKeyLanding);
|
||||||
|
// }
|
||||||
|
|
||||||
let d = JSON.parse(JSON.stringify(decodedToken));
|
// let d = JSON.parse(JSON.stringify(decodedToken));
|
||||||
// console.log("==== username from cookies ====", d);
|
// // console.log("==== username from cookies ====", d);
|
||||||
username = d.username;
|
// username = d.username;
|
||||||
|
|
||||||
} else if (uid) {
|
// } else if (uid) {
|
||||||
const bytes = CryptoJS.AES.decrypt(uid, secretKey);
|
const bytes = CryptoJS.AES.decrypt(uid, secretKey);
|
||||||
const decrypted = bytes.toString(CryptoJS.enc.Utf8);
|
const decrypted = bytes.toString(CryptoJS.enc.Utf8);
|
||||||
username = decrypted;
|
const username = decrypted;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const oldssotoken = cookies['oldssotoken'];
|
const oldssotoken = cookies['oldssotoken'];
|
||||||
const oldcid = cookies['oldcid'];
|
const oldcid = cookies['oldcid'];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue