Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!