I am trying To build an SSO scenario using NodeJS using this an example URL: https://jira.amazone.de/
When you access this page the website will ask you to enter a username and password and in the second step it will ask you for a pin code from google authenticator
my goal is to keep listening to the page and when the user enter the pin code I should read a cookie value to check if the user is signed in or no
I am having a problem to keep listening to the page while the user login
the below code is what I did so far but it will only list the cookie in the first page which is before even the user login
app.get("/ssologin", function (req, res) {
// var url = req.headers["url"];
// var lastChar = url.charAt(url.length - 1);
// if (lastChar == "/") {
// url = url.slice(0, -1);
// }
res.redirect("https://jira.amazone.de")
res.on("finish", () => {
console.log("finshed")
const cookies = parseCookies(req);
console.log(cookies)
})
})
function parseCookies(request) {
const list = {};
const cookieHeader = request.headers?.cookie;
if (!cookieHeader) return list;
cookieHeader.split(`;`).forEach(function (cookie) {
let [name, ...rest] = cookie.split(`=`);
name = name?.trim();
if (!name) return;
const value = rest.join(`=`).trim();
if (!value) return;
list[name] = decodeURIComponent(value);
});
return list;
}