passport-google-oauth2 icon indicating copy to clipboard operation
passport-google-oauth2 copied to clipboard

userProfileURL is not working

Open Npanda04 opened this issue 3 years ago • 15 comments

passport.use(new GoogleStrategy({ clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost/auth/google/secrets" userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo" },

Npanda04 avatar Jul 31 '21 20:07 Npanda04

passport.use(new GoogleStrategy({ clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost/auth/google/secrets", userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo" },

mdozairq avatar Aug 04 '21 17:08 mdozairq

userProfileURL is not working

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" },

amitdhoke avatar Sep 01 '21 18:09 amitdhoke

You don't need to use "userProfileURL" anymore, as the latest version (v2.0.0) of the npm package "passport-google-oauth20" solves the Google+ account issue which was there couple of years before.

Please refer this article by one of the collaborators for more.

ghost avatar Sep 09 '21 02:09 ghost

The "userProfileURL" is no longer required, that issue came back in 2018, when google was deprecating it's google + services. This issue has been fixed now with the new npm package

AnuragR-bitary avatar Sep 21 '21 07:09 AnuragR-bitary

The issue was "Google+ deprecation " so this link was the solutions "userProfileURL:"https://www.googleapis.com/oauth2/v3/userinfo" for that . This issue was fixed we have no longer need this "userProfileURL".

jaideep0101 avatar Nov 08 '21 04:11 jaideep0101

Register or Login button won't load to google auth login page just keep loading at localhost please how do i fix this is my import correct? i'm using ES6

import { Strategy as GoogleStrategy } from "passport-google-oauth20"

passport.use(new GoogleStrategy({ clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_S, callbackURL: "http://localhost:3000/auth/google/secrets" }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ googleId: profile.id }, function (err, user) { console.log(user); return cb(err, user); }); } ));

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

InfoColony avatar Nov 07 '22 13:11 InfoColony

Even I am facing the same issue. My google auth wont work on both login and register page, but the other functionalities like login and register using mongodb works fine. Someone please help with this issue!!

Reference: Currently doing the Angela Yu's Web Development course where she uses google oauth 2.0 to help in logging in with Google

MitraPandit avatar Nov 19 '22 10:11 MitraPandit

  1. Change app.get('/auth/google") : app.get("/auth/google", passport.authenticate('google',{ scope: ["profile"] }), function(req, res) { // Successful authentication, redirect to secrets. res.redirect("/auth/google/secrets"); });

  2. Use : passport.serializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user)); Instead of: passport.serializeUser(User.serializeUser()); passport.deserializeUser(User.deserializeUser());

  3. Also, remove: userProfileURL :"https://www.googleapis.com/oauth2/v3/userinfo" from GoogleStrategy. It is no longer needed. Google Auth popup must work now.

aishikanandi avatar Dec 22 '22 09:12 aishikanandi

  1. Change app.get('/auth/google") : app.get("/auth/google", passport.authenticate('google',{ scope: ["profile"] }), function(req, res) { // Successful authentication, redirect to secrets. res.redirect("/auth/google/s

first part what to change? im not still not getting the proper output

ShubhamSharma2003 avatar Mar 07 '23 14:03 ShubhamSharma2003

You no longer need to use "userProfileURL" because the most recent version (v2.0.0) of the npm package resolves the Google+ account issue that existed a few years ago.

PetrovEvgeniy avatar Mar 10 '23 22:03 PetrovEvgeniy

@ShubhamSharma2003 just use /auth/google/secrets in app.get("/auth/google/secrets", passport.authenticate("google", {failureRedirect: "/login"}), function(req, res) { res.redirect("/secrets"); } )

JustVibhor avatar Apr 18 '23 10:04 JustVibhor

userProfileURL :"https://www.googleapis.com/oauth2/v3/userinfo" from GoogleStrategy. It is no longer needed.

rogue-wild avatar May 03 '23 23:05 rogue-wild

Register or Login button won't load to google auth login page just keep loading at localhost please how do i fix this is my import correct? i'm using ES6

import { Strategy as GoogleStrategy } from "passport-google-oauth20"

passport.use(new GoogleStrategy({ clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_S, callbackURL: "http://localhost:3000/auth/google/secrets" }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ googleId: profile.id }, function (err, user) { console.log(user); return cb(err, user); }); } ));

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

takemeforward avatar Jun 06 '23 17:06 takemeforward

TokenError: Bad Request at OAuth2Strategy.parseErrorResponse (C:\Users\User\Desktop\Secrets - Starting Code\node_modules\passport-oauth2\lib\strategy.js:373:12) at OAuth2Strategy._createOAuthError (C:\Users\User\Desktop\Secrets - Starting Code\node_modules\passport-oauth2\lib\strategy.js:420:16) at C:\Users\User\Desktop\Secrets - Starting Code\node_modules\passport-oauth2\lib\strategy.js:177:45 at C:\Users\User\Desktop\Secrets - Starting Code\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (C:\Users\User\Desktop\Secrets - Starting Code\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (C:\Users\User\Desktop\Secrets - Starting Code\node_modules\oauth\lib\oauth2.js:157:7) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

my code:
const express = require('express');

const bodyparser = require('body-parser'); const ejs = require('ejs'); const mongoose = require('mongoose'); const user = require('./database'); const encrypt = require('mongoose-encryption'); const session = require('express-session'); const passport = require('passport'); const passportlocalmongoose = require('passport-local-mongoose'); const GoogleStrategy = require('passport-google-oauth20').Strategy;

const app = express();

app.set('view engine', 'ejs');

app.use(bodyparser.urlencoded({extended:true})); app.use(express.static('public'));

app.use(session({ secret:'mylittlesecret', resave:false, saveUninitialized:false }));

app.use(passport.initialize()); app.use(passport.session());

mongoose.connect('mongodb://127.0.0.1:27017/UserDB').then(()=>{ console.log('connected to UserDB ...........') }).catch(err => console.log(err));

passport.use(user.createStrategy());

passport.serializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user));

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

app.get('/',(req,res)=>{ res.render('home'); })

//google authentication app.get("/auth/google", passport.authenticate('google',{ scope: ["profile"] }), function(req, res) { // Successful authentication, redirect to secrets. res.redirect("/auth/google/secrets"); });

app.get('/auth/google/secrets', passport.authenticate('google', { failureRedirect: '/login' }), function(req, res) { // Successful authentication, redirect home. res.redirect('/secrets'); });

please I need help

Kenneycod avatar Jul 21 '23 07:07 Kenneycod

Try replacing : passport.serializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user));

With: passport.serializeUser(function(user, cb) { process.nextTick(function() { return cb(null, { id: user.id, username: user.username, picture: user.picture }); }); });

passport.deserializeUser(function(user, cb) { process.nextTick(function() { return cb(null, user); }); });

ShReYaSaLoNi avatar Jul 29 '23 14:07 ShReYaSaLoNi