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

Passport + Google OAuth2 + AWS Cognito

Open silviopaganini opened this issue 8 years ago • 6 comments

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!

silviopaganini avatar Feb 02 '17 15:02 silviopaganini

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

bwlt avatar Jun 23 '17 14:06 bwlt

thanyou @bwlt It helped me

ashishnumino avatar Nov 14 '17 08:11 ashishnumino

thank you @bwlt it helped me

tsamaya avatar Jun 25 '18 16:06 tsamaya

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

ahummel25 avatar Jun 20 '19 15:06 ahummel25

Wow it works perfect

Jukakombo avatar May 19 '20 19:05 Jukakombo

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

Jukakombo avatar May 19 '20 19:05 Jukakombo