javascriptnode.jsoauth-2.0passport.js

Passport - Node.js not returning Refresh Token


I am trying to return a refreshToken using the passport module of node.js. However I am using the code below and I am unable to log any refresh token but the access token works fine. Is there any way to specify the access-type offline for this module to hopefully return this?

var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
 passport.use(new GoogleStrategy({
 clientID: GOOGLE_CLIENT_ID,
 clientSecret: GOOGLE_CLIENT_SECRET,
 callbackURL: "http://myurl/auth/callback"
 },
 function(accessToken, refreshToken, profile, done) {                                                            
  console.log(refreshToken);
  process.nextTick(function () {
      return done(null, [{token:accessToken}, {rToken:refreshToken}, {profile:profile}]);
  });
}
));

This returns the refreshToken as undefined.

Any help would be greatly appreciated.


Solution

  • This was solved with this link:

    https://github.com/jaredhanson/passport/issues/42

    specifically:

    passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.profile',
                                          'https://www.googleapis.com/auth/userinfo.email'],
                                          accessType: 'offline', approvalPrompt: 'force' });
    

    Jared Hanson - bless you.