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

userProfileURL is not working #83

Open
Npanda04 opened this issue Jul 31, 2021 · 15 comments
Open

userProfileURL is not working #83

Npanda04 opened this issue Jul 31, 2021 · 15 comments

Comments

@Npanda04
Copy link

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
Copy link

mdozairq commented Aug 4, 2021

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

@amitdhoke
Copy link

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

@ghost
Copy link

ghost commented Sep 9, 2021

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.

@AnuragR-bitary
Copy link

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

@jaideep0101
Copy link

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".

@InfoColony
Copy link

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"] })
})

@MitraPandit
Copy link

MitraPandit commented Nov 19, 2022

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

@aishikanandi
Copy link

aishikanandi commented Dec 22, 2022

  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.

@ShubhamSharma2003
Copy link

  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

@PetrovEvgeniy
Copy link

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.

@JustVibhor
Copy link

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

@rogue-wild
Copy link

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

@takemeforward
Copy link

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"] })
);

@Kenneycod
Copy link

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

@ShReYaSaLoNi
Copy link

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);
});
});

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