我如何获得刷新令牌?

时间:2019-01-16 15:38:15

标签: node.js oauth-2.0 salesforce

我正在尝试从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 }

0 个答案:

没有答案