Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 41f2d35

Browse files
committed
Merge pull request #1 from rickbergfalk/pr/95
enable OAuth to work with --base-url
2 parents 63b5a2c + 950b241 commit 41f2d35

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

routes/oauth.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var passportGoogleStrategy = require('passport-google-oauth2').Strategy;
22

33
module.exports = function (app, passport, router) {
44
var db = app.get('db');
5-
5+
var baseUrl = app.get('baseUrl');
6+
67
if (!process.env.GOOGLE_CLIENT_ID || !process.env.GOOGLE_CLIENT_SECRET) {
78
console.log("Disabling Google authentication streategy, since there's no GOOGLE_CLIENT_ID or no GOOGLE_CLIENT_SECRET in ENV.");
89
return;
@@ -13,7 +14,7 @@ module.exports = function (app, passport, router) {
1314
passport.use(new passportGoogleStrategy({
1415
clientID : process.env.GOOGLE_CLIENT_ID,
1516
clientSecret : process.env.GOOGLE_CLIENT_SECRET,
16-
callbackURL : process.env.PUBLIC_URL + "/auth/google/callback",
17+
callbackURL : process.env.PUBLIC_URL + baseUrl + "/auth/google/callback",
1718
passReqToCallback : true
1819
},
1920
function(request, accessToken, refreshToken, profile, done) {
@@ -67,7 +68,7 @@ module.exports = function (app, passport, router) {
6768

6869
router.get('/auth/google/callback',
6970
passport.authenticate('google', {
70-
successRedirect: '/',
71-
failureRedirect: '/signin'
71+
successRedirect: baseUrl + '/',
72+
failureRedirect: baseUrl + '/signin'
7273
}));
7374
};

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ app.use(function (req, res, next) {
121121
// if not signed in redirect to sign in page
122122
if (req.isAuthenticated()) {
123123
next();
124-
} else if (req._parsedUrl.pathname === config.baseUrl + '/signin' || req._parsedUrl.pathname === config.baseUrl + '/signup' || req._parsedUrl.pathname.indexOf('/auth/') == 0) {
124+
} else if (req._parsedUrl.pathname === config.baseUrl + '/signin' || req._parsedUrl.pathname === config.baseUrl + '/signup' || req._parsedUrl.pathname.indexOf(config.baseUrl + '/auth/') == 0) {
125125
next();
126126
} else if (app.get('openRegistration')) {
127127
// if there are no users whitelisted, direct to signup

0 commit comments

Comments
 (0)