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

Oauth error when deploying to heroku #35

Open
f-llewellyn opened this issue Nov 3, 2021 · 1 comment
Open

Oauth error when deploying to heroku #35

f-llewellyn opened this issue Nov 3, 2021 · 1 comment

Comments

@f-llewellyn
Copy link

How to reproduce

I'm attempting to deploy this application to heroku. I have successfully deployed the application to heroku and added the redirectURI to my google cloud environment.

My problem

When it comes to logging in through Oauth, I receive the error "Error 400: redirect_uri_mismatch". This is because heroku listens for an HTTP request and not an HTTPS request, and google requires HTTPS when in production.

image

Steps taken so far

I have changed the callbackURI in /config/passport.js to force HTTP when in production, and changed proxy to true:

passport.js

const GoogleStrategy = require("passport-google-oauth20").Strategy
const mongoose = require("mongoose")
const User = require("../models/User")

module.exports = function (passport) {
    if (process.env.NODE_ENV === "development") {
        passport.use(new GoogleStrategy({
            clientID: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            callbackURL: "http://localhost:3000/auth/google/callback",
            proxy: true
        },
            // original params
    } else {
        passport.use(new GoogleStrategy({
            clientID: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            callbackURL: "http://polar-forest-68113.herokuapp.com/auth/google/callback",
            proxy: true
        },
            // original params
}

Just wondering if anyone could help me with this, cheers 😁

@techysiddhant
Copy link

You just need to past the redirect_URI into the google OAuth
uri oauth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants