我正在尝试从Salesforce获取刷新令牌。我有一个,但是,我想下次自动刷新。
'use strict'
const sf = require('node-salesforce');
var authCreds = {
accessToken: "",
instanceUrl: "",
refreshToken: ""
};
exports.login = (callback) => {
var username = "myusername";
var password = "password";
var conn = new sf.Connection({
oauth2: {
clientId: 'clientID',
clientSecret: 'SecretID',
redirectUri: 'MyRedirectURl'
},
instanceUrl: 'InstanceUrl',
accessToken: 'accestoken',
//this refresh token i am generating for the first time from the POSTMAN
refreshToken: 'my token'
});
conn.on("refresh", function (accessToken, res) {
console.log('---res-refresh token');
// Refresh event will be fired when renewed access token
// to store it in your storage for next request
});
conn.login(username, password, function (err, userInfo) {
if (err) {
console.error(err);
return callback(err);
}
// Now you can get the access token and instance URL information.
// Save them to establish connection next time.
authCreds.accessToken = conn.accessToken;
authCreds.instanceUrl = conn.instanceUrl;
// ...
return callback();
});
}
exports.get = () => { return authCreds }