jaredhanson / passport-google-oauth2

Google authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-google-oauth20/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oauth20&utm_content=about
MIT License
812 stars 154 forks source link

Sign Up with google not working #74

Closed dastageer-eth closed 3 years ago

dastageer-eth commented 3 years ago

Trying to add Google Login to the Website, I have created Project on Google Developers Console, Created the OAuth Credential and added the Client_ID and Client_Secret to.env file.

Code below :

passport.use( new GoogleStrategy( { clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost:3000/auth/google/secrets", userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo", }, function (accessToken, refreshToken, profile, cb) { User.findOrCreate({ googleId: profile.id }, function (err, user) { return cb(err, user); }); } ) );

I have also added the plugin for findorCreate:

const findOrCreate = require("mongoose-findorcreate"); userSchema.plugin(findOrCreate);

callback URL is also proper: image

And finally this my get method.

app.get("/auth/google", function (req, res) { passport.authenticate("google", { scope: ["profile"] }); });

kevinscottuk commented 3 years ago

@KrakenLynch

Looks like we may be working on the same demo project "Secrets"?

I have just implemented this and it is working fine.

Have you installed the NPM package passport-google-oauth20?

Have you inserted: const GoogleStrategy = require('passport-google-oauth20').Strategy;

Happy to take a look at all your code to try and help.

bialabs commented 3 years ago

same here, on same demo tutorial. Have you fixed the issue? in my case when i click on Sign in with Google (http://localhost:3000/auth/google) the Google login is not shown. The page is always in loading

bialabs commented 3 years ago

solved by using

app.get("/auth/google", 
passport.authenticate("google", { scope: ["profile"] });
);

instead of

app.get("/auth/google", function (req, res) {
passport.authenticate("google", { scope: ["profile"] });
});

anyone can explain why the second approach was not working?

SaketManiyar commented 3 years ago

solved by using

app.get("/auth/google", 
passport.authenticate("google", { scope: ["profile"] });
);

instead of

app.get("/auth/google", function (req, res) {
passport.authenticate("google", { scope: ["profile"] });
});

anyone can explain why the second approach was not working?

see the documentation its given there