Skip to content
Snippets Groups Projects
Commit a9eabb0b authored by Federico Hurtado's avatar Federico Hurtado
Browse files

Bypass cas authentication when using localhost

parent ee984cd0
No related branches found
No related tags found
1 merge request!2able to bypass cas in localhost
...@@ -5,4 +5,4 @@ DB_PASSWORD=corps_db_password ...@@ -5,4 +5,4 @@ DB_PASSWORD=corps_db_password
DB_NAME=corps_directory_db DB_NAME=corps_directory_db
PORT=3000 PORT=3000
FRONTEND_URL=localhost:8080 FRONTEND_URL=http://localhost:8080
\ No newline at end of file \ No newline at end of file
...@@ -9,6 +9,28 @@ const casLogin = function (req, res, next) { ...@@ -9,6 +9,28 @@ const casLogin = function (req, res, next) {
// hard-coded for now. // hard-coded for now.
const JWT_SECRET = "secret_key"; const JWT_SECRET = "secret_key";
// if on localhost, accept the authentication and give a key
console.log("user: ", process.env.DB_USER);
if (process.env.DB_USER === "corps_directory_dev") {
// payload for the JWT token
const payload = {
id: 1,
role: "admin",
username: "localhostuser",
};
// sign the token with secret key
const token = jwt.sign(payload, JWT_SECRET, { expiresIn: "1h" });
console.log("sending token for use in localhost");
console.log("Frontend: ", process.env.FRONTEND_URL);
res.redirect(`${process.env.FRONTEND_URL}/home?token=${token}`);
return;
}
// call the authenticate function with CAS // call the authenticate function with CAS
passport.authenticate("cas", function (err, user, info) { passport.authenticate("cas", function (err, user, info) {
if (err) { if (err) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment