Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda