Commit d5df6b3b authored by Simen Vevik's avatar Simen Vevik
Browse files

feide works, but express creates new session on redirect

parent 136ab4f4
......@@ -4,7 +4,9 @@ const jwt = require("jsonwebtoken");
const config = require("config");
module.exports = function(req, res, next) {
console.log(req.isAuthenticated());
// console.log(req.session);
console.log(req.session);
console.log("auth.js is Auth(): " + req.isAuthenticated());
// Check if user is logged into Feide
if (req.isAuthenticated()) {
console.log(req.session.passport.user);
......@@ -12,7 +14,7 @@ module.exports = function(req, res, next) {
// Check if user is logged in
} else {
console.log("Not feide user");
console.log("auth.js not feide user");
// Get token from header
const token = req.header("x-auth-token");
......
......@@ -4,10 +4,10 @@ const mysql = require("mysql");
const config = require("config");
const connection = mysql.createConnection({
host: config.get("db.host"),
user: config.get("db.user"),
password: config.get("db.password"),
database: config.get("db.database")
host: config.get("db-remote.host"),
user: config.get("db-remote.user"),
password: config.get("db-remote.password"),
database: config.get("db-remote.database")
});
// connection.connect();
......
......@@ -29,22 +29,4 @@ module.exports = function(passport) {
}
)
);
// passport.use(
// new SamlStrategy(
// {
// path: config.get("passport.path"),
// entryPoint: config.get("passport.entryPoint"),
// issuer: config.get("passport.issuer")
// // cert: config.get("passport.cert")
// },
// function(profile, done) {
// findByEmail(profile.email, function(err, user) {
// if (err) {
// return done(err);
// }
// return done(null, user);
// });
// }
// )
// );
};
This diff is collapsed.
......@@ -12,18 +12,18 @@
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"config": "^3.2.0",
"config": "^3.2.4",
"cookie-parser": "^1.4.4",
"express": "^4.17.1",
"express-session": "^1.16.2",
"express-validator": "^6.1.1",
"express-session": "^1.17.0",
"express-validator": "^6.3.0",
"fs": "0.0.1-security",
"jsonwebtoken": "^8.5.1",
"mysql": "^2.17.1",
"passport": "^0.4.0",
"passport-saml": "^1.1.0"
"passport": "^0.4.1",
"passport-saml": "^1.2.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
"nodemon": "^1.19.4"
}
}
......@@ -17,16 +17,15 @@ Routes used by Feide IDP
// @access Public
router.post(
"/login/callback",
bodyParser.urlencoded({ extended: true }),
bodyParser.urlencoded({ extended: false }),
passport.authenticate("saml", {
failureRedirect: config.get("passport.SLO_redirect")
// failureFlash: true
}),
function(req, res) {
console.log(req.isAuthenticated());
console.log("SAML auth sucess");
req.session.save(() => {
res.redirect(config.get("passport.SSO_redirect"));
req.session.save(err => {
if (!err) {
res.redirect(config.get("passport.SSO_redirect"));
}
});
}
);
......@@ -38,7 +37,6 @@ router.get(
"/login",
passport.authenticate("saml", {
failureRedirect: "/",
successRedirect: "/",
failureFlash: true
}),
(req, res) => {
......
......@@ -39,13 +39,20 @@ const credentials = {
require("./middleware/passport")(passport);
app.use(
session({
secret: config.get("app.session"),
resave: false,
saveUninitialized: false,
cookie: {}
})
);
// Init Middleware
// Express comes with npm body-parser, which is used to parse http post requests
// Parse incomming requests with req.body
app.use(express.json({ extended: false }));
// app.use(cookieParser(config.get("app.session")));
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(function(req, res, next) {
// Match the domain you will make the request from
......@@ -59,14 +66,6 @@ app.use(function(req, res, next) {
next();
});
app.use(
session({
resave: true,
saveUninitialized: true,
secret: config.get("app.session")
})
);
// Init passport
app.use(passport.initialize());
app.use(passport.session());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment