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
826 stars 153 forks source link

Passport + Google OAuth2 + AWS Cognito #20

Open silviopaganini opened 7 years ago

silviopaganini commented 7 years ago

Hi there

I'm getting this NotAuthorizedException: Invalid login token. Not a valid OpenId Connect identity token.

when trying to use the accessToken you return to create an Identity on Cognito, any ideas?

I found on AWS forum this

UPDATE: Finally figured out the issue. The token I was using was incorrect. It should be id_token that is returned from Google and not the access_token or refresh_token. 

any ideas of what that could be or how it could be fixed?

thanks!

bwlt commented 7 years ago

Found a solution! The correct token to use is not the standard accessToken inside the verify function (second argument) of the strategy:

passport.use(new GoogleStrategy({
    clientID:     GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL:  CALLBACK_URL,
  },
  (accessToken, refreshToken, params, profile, done) => {
    process.nextTick(() => done(null, {
      accessToken,
      refreshToken,
      idToken: params.id_token,
      profile
    }))
  }
))

you can find the correct token id_token in the params argument.

Hope it helps

ashishnumino commented 7 years ago

thanyou @bwlt It helped me

tsamaya commented 6 years ago

thank you @bwlt it helped me

ahummel25 commented 5 years ago

I still get this error. I don't see params being passed back in the Google Strategy callback. Any ideas?

Jukakombo commented 4 years ago

Wow it works perfect

Jukakombo commented 4 years ago

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