Heroku Google OAuth Error Heroku Google OAuth Error heroku heroku

Heroku Google OAuth Error


I have the same issue with this problem too. I solve it by define an absoluteURI on the config keys. because google look at url callback at https:// and heroku path is http:// which it should be fix when you add proxy: true but it is not.

On the config keys add

dev: absoluteURI: localhost:5000

prod: absoluteURI: http://herokupath

// .use is generic registerpassport.use(  new GoogleStrategy(    {      clientID: keys.googleClientID,      clientSecret: keys.googleClientSecret,      callbackURL: absoluteURI + "/auth/google/callback",      proxy: true     },


I believe the problem is that your app on heroku is only listening for http requests. If your link to the OAuth page has the form "https://your-domain.com/auth/google", then your app's routes will not match against that route (because of the https) and so your app will show a blank page, just like it will show for any route that it's not listening for.

One way to get around this problem and still use https (and therefore still show the secure logo next to the url) is to use https for every link except for this OAuth link. Your get and post requests within the app will be using http, but any link visible on the url will use https. Something like this would work:

app.use(function(req, res, next) {        if (process.env.NODE_ENV === "production") {            const reqType = req.headers["x-forwarded-proto"];            // if not https redirect to https unless logging in using OAuth            if (reqType !== "https") {                req.url.indexOf("auth/google") !== -1                  ? next()                  : res.redirect("https://" + req.headers.host + req.url);            }         } else {            next();        }    });  

And any frontend link that points to the OAuth login page should be an http link


Please take a look at this SO answer. It looks like your scope params need to be modified for the google auth to work.