-
-
Save ahuggins-nhs/324a9fefb102c53acfb0b7a3b721b801 to your computer and use it in GitHub Desktop.
jsforce with jwt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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