MonkeyBonkey
MonkeyBonkey

Reputation: 47871

Why is refreshtoken always null using the Auth0 passport strategy

Using the auth0 passport strategy

https://github.com/auth0/passport-auth0

My callback always has null for a refresh token. Calling the auth0 lock function directly gives me a refreshtoken as expected, however using this oauth passport strategy doesn't return a refreshtoken. Do I need to pass an offline_access scope to auth0 - and if so, how do I pass it in using the Auth0Strategy?

passport.use(new Auth0Strategy({
    domain:       config.auth0.domain,
    clientID:     config.auth0.clientId,
    clientSecret: config.auth0.secret,
    callbackURL:  '/login/return'
  },
  function(accessToken, refreshToken, extraParams, profile, done) {
    console.log('refresh token is always null', refreshToken);
 }
});

Upvotes: 0

Views: 603

Answers (1)

Eugenio Pace
Eugenio Pace

Reputation: 14212

Yes, you need to request one (by adding scope=offline_access). You do this when you send the initial authorization request (e.g. via Lock, or auth0.js, or by simply following link with the right parameters). It is not dependent on passport really. Makes sense?

e.g. try with this:

app.get('/login',
  passport.authenticate('auth0', {scope: 'offline_access'}), function (req, res) {
  res.redirect("/");
});

Upvotes: 1

Related Questions