After placing the refresh token, access token and the instance URL in the session, I have the following code:
app.get('/api/v1/refresh', function (req, res) {
const conn = new jsforce.Connection({
oauth2: {
clientId: process.env.SALESFORCE_CONSUMER_ID,
clientSecret: process.env.SALESFORCE_CONSUMER_SECRET,
redirectUri: process.env.SALESFORCE_CALLBACK_URL
},
instanceUrl: req.session.user.salesforce.instanceUrl,
accessToken: req.session.user.salesforce.accessToken,
refreshToken: req.session.user.salesforce.refreshToken
})
conn.oauth2.refreshToken(req.session.user.refreshToken, (err, results) => {
if (err) {
return res.json({ error: err.message })
}
res.json(results)
})
})
I'm aware you don't have to refresh with jsforce, but I'm just trying to see the tokens work. In this case, I get the error: invalid_grant: expired access/refresh token
- but the token is only seconds old?
Using conn.sobject
, conn.query
or conn.search
results in no callback being called.
The scopes setup for the OAUTH2 flow are:
- API
- profile
- web
- refresh_token, offline_access
Thank you in advance for your help.