salesforce.getAccessToken
Generates a token if there is no permanent access token set.
Description
salesforce.getAccessToken(config: object, scope: string, callback: Function)
Parameters
config
Contains the authentication details for your Salesforce application in an object called “installed”, as follows:
- redirect_uris: array(),
- client_id: string,
- client_secret: string,
- auth_uri: string,
- token_uri: string
scope
The OAuth request scope. The default should be: ‘api’.
callback
A function that receives the Salesforce access token as parameter when the authentication returns successfully. Other Salesforce related calls should go here.
Return values
Returns a Salesforce access token if the login was successful.
Example
const config = {
installed: {
redirect_uris: ['https://{customer}.asp.virtual-call-center.eu/salesforce'],
client_id: '2MVG96_7YM2sI9wQBiYQUxCZoLWXkUX25vtmJvHyRJU0BRSiY_QWHS2AR_kt8eD9LJRhLkLSFKCADMeFwFiyr',
client_secret: '1209H7AD57CP54240BEACB346C8EL7215A1193944F109F3Q3927A85E3051F741',
auth_uri: 'https://login.salesforce.com/services/oauth2/authorize',
token_uri: 'https://login.salesforce.com/services/oauth2/token',
}
};
salesforce.getAccessToken(config, 'api', function(accessToken) {
var request = vcc.httpRequest();
request.open('GET', 'https://eu26.salesforce.com/services/data/v39.0/sobjects/User');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'Bearer '+accessToken);
request.onload = function(e) {
var response = JSON.parse(request.responseText);
dump(response);
};
request.send();
});
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.