Как получить токен обновления? - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь получить токен обновления от 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 }
...