Node.js "passport-google-oauth2" delivers "failed to fetch user profile" error in Express application
I just fortunately found a similar issue at
jaredhanson/passport-google-oauth, which gave me the idea to go to the Google's project console and simply enable the Google+ API
, which was "turned off" (oh me!!, naive developer of his first application based on Google+). That was the root of the problem. I tried again and the oauth2
started receiving profiles correctly.
The scope
you are using is deprecated now :
passport.authenticate('google', { successRedirect: '/',scope:
[ 'https://www.googleapis.com/auth/userinfo.email']})
);
Instead, we must use this one:
passport.authenticate('google', { successRedirect: '/',scope:
['email']
}));
You can also get the profile scope
:
passport.authenticate('google', { successRedirect: '/',scope:
[ 'email', 'profile' ]
}));