Monday 10 April 2017

Get google OAuth 2.0 refresh token using PassPortJS and Node.jS

I am having trouble getting a refresh token from Google using Passport JS. I have been removing access in my account permissions to make sure it is a first time login. I keep getting "undefined" for the token. Here is the code I have at the moment.

Passport.use(new GoogleStrategy({
    clientID:     "xxxxx.apps.googleusercontent.com",
    clientSecret: "xxxxx",
    callbackURL: `https://localhost:${port}/auth/google/callback`,
    accessType: 'offline',
    passReqToCallback: true
  },
  function(req,accessToken, refreshToken, profile, done) {

    var tokens = {
      access_token: accessToken,
      refresh_token: refreshToken
    }
    console.log(tokens)
    oauth2Client.setCredentials(tokens);


    done(err = false, user = true)


}));

If anyone has experience working OAuth into their web apps that could lend a hand it would be greatly appreciated



via Peter3

No comments:

Post a Comment