Skip to content

Commit

Permalink
Remove routes for unused auth strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
js0mmer committed Dec 20, 2023
1 parent a857420 commit c4f36dc
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,69 +80,6 @@ router.get('/auth/google/callback', function (req, res) {
)(req, res);
});

/**
* Initiate authentication with Facebook
*/
router.get('/auth/facebook', function (req, res) {
req.session.returnTo = req.headers.referer;
passport.authenticate('facebook', { scope: ['email'] })(req, res);
});

/**
* Callback for Facebook authentication
*/
router.get(
'/auth/facebook/callback',
passport.authenticate('facebook', { failureRedirect: '/', session: true }),
successLogin,
);

/**
* Initiate authentication with Github
*/
router.get('/auth/github', function (req, res) {
console.log('START AUTH GITHUB');
req.session.returnTo = req.headers.referer;
passport.authenticate('github')(req, res);
});

/**
* Callback for Github authentication
*/
router.get('/auth/github/callback', function (req, res) {
passport.authenticate(
'github',
{ failureRedirect: '/', session: true },
// provides user information to determine whether or not to authenticate
function (err, user, info) {
console.log('Logging with Github!');
if (err) console.log(err);
else if (!user) console.log('Invalid login data');
else {
// check if user is an admin
let allowedUsers = JSON.parse(process.env.GITHUB_ADMIN_USERNAMES);
if (allowedUsers.includes(user.username)) {
console.log('GITHUB AUTHORIZED!');
// manually login
req.login(user, function (err) {
if (err) console.log(err);
else {
req.session.passport!.admin = true;
successLogin(req, res);
}
});
} else {
console.log(`INVALID USER! Expected ${allowedUsers}, Got ${user.username}`);
// failed login
let returnTo = req.session.returnTo;
delete req.session.returnTo;
res.redirect(returnTo!);
}
}
},
)(req, res);
});

/**
* Called after successful authentication
* @param req Express Request Object
Expand Down

0 comments on commit c4f36dc

Please sign in to comment.