jaredhanson / passport-google-oauth

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

TokenError in Google oauth2 #76

Open sarankup opened 9 years ago

sarankup commented 9 years ago

Hi,

I am using passport in total.js application in which all other oath works well including facebook, twitter. But when I try to login using Google account, I got "TokenError" as error.

Please advise how to solve.

alexkahn commented 9 years ago

Same here. Google Console settings are correct, works in Production but not in development.

jaredhanson commented 9 years ago

Please provide more details. Error messages and stack traces are helpful when debugging issues.

alexkahn commented 9 years ago

Sorry, just realized that:

500 TokenError at Strategy.OAuth2Strategy.parseErrorResponse (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12) 
    at Strategy.OAuth2Strategy._createOAuthError (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16) 
    at app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43 
    at app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18 
    at passBackControl (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9) 
    at IncomingMessage.<anonymous> (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7) 
    at IncomingMessage.emit (events.js:129:20) 
    at _stream_readable.js:908:16 
    at process._tickCallback (node.js:355:11)
sarankup commented 9 years ago

Hi,

For me, the google sign in page, opens and I click the account and then "Accept", again the page redirect to google login over and over again. Here goes the error message in console.

createCredentials() is deprecated, use tls.createSecureContext instead error happenTokenError

aendra-rininsland commented 9 years ago

I'm using this with generator-angular-fullstack and am getting the "createCredentials is depreciated" error as well:

GET /auth/google 302 3ms - 0b
createCredentials() is deprecated, use tls.createSecureContext instead
InternalOAuthError: failed to fetch user profile
    at /Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/lib/passport-google-oauth/oauth2.js:88:28
    at passBackControl (/Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9)
    at IncomingMessage.<anonymous> (/Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
GET /auth/google/callback?code=[obfuscated] 500 861ms - 718b

Edit: Never mind, this wasn't what was causing it to fail. It was not having the G+ API enabled in the Google API Console. This should probably be better signposted...

alexkahn commented 9 years ago

Just a note: my problem was solved.

Solution: I was using the same API credentials in both development and staging so Google wouldn't let me create a sign in on the same app (in it's eyes) from two locations.

sarankup commented 9 years ago

Hi, Any update on this. It seems my problem is not resolved.

sarankup commented 9 years ago

Does that mean, you want me to create a new app key in Google and assign?

In my case, I am just in the localhost, and not to place hosting now.

On Thu, May 14, 2015 at 3:33 AM, Alex Kahn notifications@github.com wrote:

Just a note: my problem was solved.

Solution: I was using the same API credentials in both development and staging so Google wouldn't let me create a sign in on the same app (in it's eyes) from two locations.

— Reply to this email directly or view it on GitHub https://github.com/jaredhanson/passport-google-oauth/issues/76#issuecomment-101829756 .

aendra-rininsland commented 9 years ago

@sarankup If you already have a project in the API console you're using, go to https://console.developers.google.com, click "APIs & auth", "APIs", "Google+ API", "Enable API". Otherwise create a new project and do that.

adamk33n3r commented 9 years ago

@aendrew Thanks you saved me a bunch of headache. I didn't even think of doing that.

amejiarosario commented 9 years ago

For anybody strugguling with it...

  1. You need to go API & auth > APIs and enable Google+ API.
  2. Later click on Explore this API and enable Authorize requests using OAuth 2.0 as shown image
  3. Furthermore, you need to go API & auth > APIs and enable Google+ API. Later click on Explore this API and enable Authorize requests using OAuth 2.0.

image

si74 commented 9 years ago

@alexkahn Could you elaborate a bit on how you solved this problem? Having a similar issue and I've tried all of the aforementioned steps but alas - no cigar.

imdadul commented 9 years ago

@amejiarosario Thanks. But that's not working for me. Once I select & authorize , it shows 'ON' in top right, then I refresh, it shows OFF again. Am I missing anything ?

OttlikG commented 9 years ago

Same problem here. When I switch On it immediately turn Off after page refresh.

imdadul commented 9 years ago

@OttlikG . What I found that it actually does not matter, if you turned on, you can be sure that it actually turned on. So that worked for me. And make sure that, your keys are trimmed (no space) when added into the code.

OttlikG commented 9 years ago

@imdadul Thanks, I came to the same solution one day ago.

sunitJindal commented 9 years ago

It seems to be an issue with Google it self. Am also facing the issue, every time i turn on the "Authorize requests using OAuth 2.0:" option and i refresh the page it's turned off every time... I am pretty sure as when this stupid thing is turned on, Passport would work just fine

divneet commented 9 years ago

hey , i'm facing a similar problem and can not solve ot using the given solutions . let me know what changes i can make to debug the code

divneet commented 9 years ago

@aendrew hey , do you have idea what i am doing wrong here . at Strategy.OAuth2Strategy.parseErrorResponse (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12) at Strategy.OAuth2Strategy._createOAuthError (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16) at /home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43 at /home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18 at passBackControl (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9) at IncomingMessage. (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7) at IncomingMessage.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickCallback (node.js:355:11)

divneet commented 9 years ago

hey @alexkahn can you help me out here ?

alexkahn commented 9 years ago

@divneet @si74 My issue was just having one set of credentials for an app that I had in both development and production. All I had to do was set up some API credentials for both environments. If you aren't in that scenario then I don't really know what else to tell you.

divneet commented 9 years ago

hey @OttlikG can you help me out here ?

OttlikG commented 9 years ago

I just copied the key with an additional space and that caused the problem. I'm afraid of that I can't help you.

amitbhatnagar commented 8 years ago

I get the same error when google calls my callback URL with a code

I'm using node 4.2.4 with express 4.13.3

"http:// domainname .com/login/google/callback?code=xxxxxxxxxxx"

TokenError at Strategy.OAuth2Strategy.parseErrorResponse (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12) at Strategy.OAuth2Strategy._createOAuthError (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16) at /var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43 at /var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18 at passBackControl (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9) at IncomingMessage. (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7) at IncomingMessage.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickDomainCallback (node.js:381:11)

I have tried all the workaround mentioned in this post but still getting the same error.

divneet commented 8 years ago

@amitbhatnagar try using everyauth ,since i wasn't able to work it out .

sebnapi commented 8 years ago

Make sure to check client-id and client-secret, wasted two hours on this, just because I assumed I did it right :expressionless:

krishangupta commented 7 years ago

@aendrew's solution worked for me. Thanks!

ruichao-factual commented 7 years ago

I meet a similar Error. The reason for my issue is that my server can't access google. 😭

sayingu commented 6 years ago

In my case, var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy; to var GoogleStarategy = require('passport-google-oauth').OAuth2Strategy; then it works.

sebaveg commented 6 years ago

I was an hour with the same error. My error was in callbackURL: 'auth/google/redirect'. The correct is callbackURL: '/auth/google/redirect'

sojelee commented 6 years ago

Thank you guys for all you answers, just spent 4 hours trying to get the passportjs social authentication, I managed to get twitter,facebook and github authenticating, but I got stuck on google, as I was getting to the authentication page to then got some errors, until I found this page, I had not enabled Google + API, you really all served my day

rishulmatta commented 6 years ago

I have done all of the above and I still get this error:

TokenError: Malformed auth code. at Strategy.OAuth2Strategy.parseErrorResponse (C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:376:16) at C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:166:45 at C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1056:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

  1. I have the api enabled: image

  2. I get a code in the URL:

http://localhost:5000/api/v0/auth/google/callback?code=4/AAAIYeU7JQUFZM42W16Lpb70nZQlCj5yUOt3Zgd23vufYWo1Y0d-kAwHsVzz5YJMkLYUw3CjFPrgdkDwLVYAl5I#

  1. I have the correct config and correct callbacks:

GoogleStrategy = require('passport-google-oauth20').Strategy

new GoogleStrategy({ clientID: keys.google.client_id, clientSecret: keys.google.client_secret, callbackURL: '/api/v0/auth/google/callback' },() => {});

  1. There are no spaces in my api keys

Any help is appreciated

pal-p commented 6 years ago

I had the exact same problem when deploying to heroku. Unauthorized token error means that your client secret is not entered correctly. Make sure it doesn't contain spaces when copying

shankywwww commented 6 years ago

Did anyone get client_secret is missing error. I am passing following object for google strategy

const GoogleStrategy = require('passport-google-oauth20').Strategy

passport.use ( new GoogleStrategy ({ clientID: keys.googleClientID, clent_secret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken) => { console.log(accessToken) }))

Find the error details below.

TokenError: client_secret is missing. at Strategy.OAuth2Strategy.parseErrorResponse (D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:330:12) at Strategy.OAuth2Strategy._createOAuthError (D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:377:16) at D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:166:45 at D:\Users\shasdr\Documents\FullStack\server\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (D:\Users\shasdr\Documents\FullStack\server\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (D:\Users\shasdr\Documents\FullStack\server\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:139:11)

unable to find fix. tried all the suggestions given in the above comment thread.

leonardfactory commented 5 years ago

passport.use ( new GoogleStrategy ({ clientID: keys.googleClientID, clent_secret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken) => { console.log(accessToken) }))

@shankywwww Not sure if you already solved this, however, It seems you're using client_secret but it should be clientSecret

SambhavS004 commented 5 years ago

I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help.

TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16) at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45 at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)

clearloop commented 5 years ago

check the typo of clientID and clientScrect....That's what controlled my google+ API...

dimasi commented 5 years ago

In my case:

passport.use(new GoogleStrategy({
    clientID: config.google[env].appId,
    clientSecret: config.google[env].clientSecret, // <- console.log(config.google[env].clientSecret === undefined)
    callbackURL: `${(options.baseUrl || '')}/auth/google/callback`,
    passReqToCallback: true,
}, (request, accessToken, refreshToken, profile, done) => { ... }));

Just a typo. Instead of config.google[env].clientSecret should have been config.google[env].appSecret

naveenk2k commented 5 years ago

I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help.

TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16) at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45 at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)

@SambhavS004 I'm getting the exact same error. Did you manage to fix it?

Hameed098 commented 5 years ago

is there any single man to fix this error?

sumanmahto commented 5 years ago

I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help. TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16) at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45 at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)

@SambhavS004 I'm getting the exact same error. Did you manage to fix it?

In my case, I deleted the old credentials and created new one in the same google api project. I went to this https://console.developers.google.com/apis/credentials, selected the project, deleted the existed one OAuth 2.0 client ID and created new credentials with OAuth client ID then used the new clientID & clientSecret in my code. This is working fine for me.

vikjdk7 commented 5 years ago

I also encountered same issue while trying to invoke callback function,

_TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:358:12) at Strategy.OAuth2Strategy._createOAuthError (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:405:16) at /Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:175:45 at /Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/oauth/lib/oauth2.js:191:18 at passBackControl (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/oauth/lib/oauth2.js:132:9) at IncomingMessage. (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/oauth/lib/oauth2.js:157:7) at IncomingMessage.emit (events.js:194:15) at endReadableNT (_stream_readable.js:1125:12) at process._tickCallback (internal/process/next_tick.js:63:19)_

Solution - Two solutions I found feasible which worked for me a. ``` passport.use(new GoogleStrategy({ //options for google strategy callbackURL: '/auth/google/redirect', //I forgot initial / before auth. clientID: keys.google.clientID, clientSecret: keys.google.clientSecret }, (accessToken, refreshToken, profile, done) => { //passport callback function console.log('--------- callback function fired ---------'); console.log(profile);

}))


b. credentials should be used wisely on different deployment platforms.
JayGondalia commented 4 years ago

TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:358:12) at Strategy.OAuth2Strategy._createOAuthError (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:405:16) at f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:175:45 at f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:157:7) at IncomingMessage.emit (events.js:215:7) at endReadableNT (_stream_readable.js:1183:12) at processTicksAndRejections (internal/process/task_queues.js:80:21) TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:358:12) at Strategy.OAuth2Strategy._createOAuthError (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:405:16) at f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:175:45 at f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:157:7) at IncomingMessage.emit (events.js:215:7) at endReadableNT (_stream_readable.js:1183:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)

can anyone help me how to solve >?

brookmg commented 4 years ago

This issue seems to be active since 2015. Any other strategy you guys started using instead of this for OAuth2 with google?

brookmg commented 4 years ago

I found out that this way caused because of some kind of timeout error for me. Mainly because I didn't call the done callback function passed from the strategy.

Passport.use(new GoogleStrategy({
        clientID: '', 
        clientSecret: '', 
        callbackURL: "http://localhost:3400/auth/google/callback"
    }, (accessToken , refreshToken, profile, done) => {
        console.log(`${accessToken} -> access token`);
        console.log(`${refreshToken} -> refresh token`);

        // Store user's token in the db but with more security.
        done(false, {strategy: 'google' , accessToken , refreshToken , ...profile});
    })
);
tesla809 commented 4 years ago

resetting the credentials like @sumanmahto mentioned worked for me.

hfuentes commented 4 years ago

Catch all errors...

exports.setup = () => {
    passport.use(new GoogleStrategy({
        clientID: config.client_id,
        clientSecret: config.client_secret,
        callbackURL: config.callback_uri
    }, (accessToken, refreshToken, profile, done) => {
        if (profile && profile._json && profile._json.email) {
            return User.findOne({ email: profile._json.email }).exec().then(user => {
                user.displayName = profile._json.name
                user.photoURL = profile._json.picture
                return user.save()
            }).then(savedUser => done(null, savedUser)).catch(done)
        } else return done()
    }))
}
vishwa3 commented 4 years ago

I am also getting the same error TokenError: Bad Request Please let me know if google sign in can be implemented without using passport

wenqiuZhou commented 4 years ago

I encountered the same problem because I removed "return cb(err, user);" code as below works well: findOrCreate is from "mongoose-findorcreate"

passport.use(new GoogleStrategy({ clientID: process.env.ClientID, clientSecret: process.env.ClientKey, callbackURL: "xxxx" 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); ; }); } ));

RanjeetSingh00 commented 4 years ago

Hey Guys! This Error have Best Solution:

Replace Following Code:

passport.use(new GoogleStrategy({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: '/auth/google/callback' }, async (accessToken, refreshToken, profile, done) => { // Users full Profile by Google // console.log(profile) const newUser = { googleId: profile.id, displayName: profile.displayName, firstName: profile.name.givenName, lastName: profile.name.familyName, image: profile.photos[0].value }

           console.log(newUser)
           // you forgot this
          done(null, null)