Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
Passport.js OAuth2Strategy response not containing refresh token

Currently, I have an Oauth2 flow for an API. The code works but I dont believe it is working the way it should.

const OAuth2Strategy = require('passport-oauth2');

passport.use(new OAuth2Strategy({
    authorizationURL: authorizationURL, 
    tokenURL: tokenURL, 
    clientID: clientId, 
    clientSecret: clientSecret, 
    callbackURL: callbackURL,    
}, function(accessToken, refreshToken, results, profile, callback) {
    return callback(null, results);
}))

app.get('/auth/api', passport.authenticate('oauth2', {failureRedirect: '/fail', successRedirect: '/', scope: ['profile']}));

I manage to get an accestoken, refreshtokenand results in the callback function, however, minor problems are occuring. The first is that profile is returning an empty object {}. I dont believe passport can do anything about this due to the stratergy not being native to the API. The other problem is that results is returning the accesstoken and its expiration but it doesnt return the refresh token in the results. The thing I dont understand is that the refreshtoken callback parameter is returining the refresh token but the result doesnt contain it.

What I expect to recieve accoring to the api documentation is:

{
  access_token: "...",
  expires_in: 300,
  refresh_expires_in: 1800,
  refresh_token: "...",
  token_type: "bearer",
  'not-before-policy': 0,
  scope: "profile"
}

but what im getting is:

{
  access_token: '...',
  expires_in: 900,
  refresh_expires_in: 0,
  token_type: 'Bearer',
  'not-before-policy': 0,
  scope: 'offline_access email profile'
}

I could just merge the refreshtoken and the results together but if this is the current outcome, surely im doing something wrong. Is this to do with the stratergy im using?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

According to the docs, the callback receives only four parameters:

function(accessToken, refreshToken, profile, cb) {
...
}

There is no results parameter. Still, you can pass to your callback (cb in the code above) anything you like from the things you received in the passport's callback. If you have the refresh token in the refreshToken parameter, then just pass it to your cb if you need it there.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda