Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.get("/issue/", (req: any, res: any, next: any): void => {
// passport.authenticate("session");
if (req.query.SAMLRequest !== undefined && req.query.SAMLRequest !== null) {
if ((req.user === undefined || req.user === null)) {
try {
// tslint:disable-next-line: max-line-length
samlp.parseRequest(req, samlpoptions, async (_err: any, samlRequestDom: any): Promise => {
res.cookie("originalUrl", req.originalUrl, { maxAge: 900000, httpOnly: true });
res.redirect("/");
});
} catch (error) {
res.body(error.message);
res.end();
console.error(error);
}
} else {
// continue with issuing token using samlp
next();
}
} else {
res.send("go away!");
res.end();
}
app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
samlp.parseRequest(req, (err: any, data: any) => {
next();
});
});
const parseSamlRequest = function(req, res, next) {
samlp.parseRequest(req, function(err, data) {
if (err) {
return res.render('error', {
message: 'SAML AuthnRequest Parse Error: ' + err.message,
error: err
});
};
if (data) {
req.authnRequest = {
relayState: req.query.RelayState || req.body.RelayState,
id: data.id,
issuer: data.issuer,
destination: data.destination,
acsUrl: data.assertionConsumerServiceURL,
forceAuthn: data.forceAuthn === 'true'
};
console.log('Received AuthnRequest => \n', req.authnRequest);