Skip to content

Instantly share code, notes, and snippets.

@ahuggins-nhs
Forked from jeffdonthemic/org_connection.js
Created April 2, 2020 16:26
Show Gist options
  • Save ahuggins-nhs/324a9fefb102c53acfb0b7a3b721b801 to your computer and use it in GitHub Desktop.
Save ahuggins-nhs/324a9fefb102c53acfb0b7a3b721b801 to your computer and use it in GitHub Desktop.
jsforce with jwt
const jsforce = require('jsforce');
const jwt = require("salesforce-jwt-bearer-token-flow");
// create the connection to the org
let conn = new jsforce.Connection();
// load the private key for the token
let privateKey = require('fs').readFileSync('./server.key', 'utf8');
jwt.getToken({
iss: process.env.CLIENT_ID,
sub: process.env.USERNAME,
aud: process.env.LOGIN_URL,
privateKey: privateKey
}, function(err, response) {
if (err) {
console.error(err);
} else {
conn.initialize({
instanceUrl: response.instance_url,
accessToken: response.access_token
});
console.log('Successfully connected to Org');
}
}
);
module.exports = conn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment