Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging login callback redirect #291

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ router.get('/auth/google',
passport.authenticate('google', {
scope: ['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'],
state: req.headers.host
})(req, res);
}
);
Expand All @@ -46,6 +47,16 @@ router.get('/auth/google',
*/
router.get('/auth/google/callback', function (req, res) {
const returnTo = req.session.returnTo;
let host: string = req.query.state as string;
// all staging auths will redirect their callback to prod since all callback URLs must be registered
// with google cloud for security reasons and it isn't feasible to register the callback URLs for all
// staging instances
// if we are not on a staging instance (on prod or local) but original host is a staging instance, redirect back to host
if (host.startsWith('staging-') && !req.headers.host?.startsWith('staging')) {
// req.url doesn't include /api/users part, only /auth/google/callback? and whatever params after that
res.redirect('https://' + host + '/api/users' + req.url);
return;
}
passport.authenticate('google', { failureRedirect: '/', session: true },
// provides user information to determine whether or not to authenticate
function (err, user, info) {
Expand Down