Skip to content

SalesForce Auth 2.0 JWT Bearer Token Flow Implementation for Node.js

License

Notifications You must be signed in to change notification settings

leandrob/node-salesforce-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce Auth 2.0 JWT Bearer Token Flow Implementation

salesforce-jwt is an minimal implementation of the OAuth 2.0 JWT Bearer Token Flow that allows you to impersonate users on SalesForce.

It is compatible with jsforce.

Installation

$ npm install salesforce-jwt

Usage

var jwtflow = require('salesforce-jwt');

var clientId = '3MVG9A2kN3Bn17hvVNDOE5FX8c9hS...30dgSSfyGi1FS09Zg'; // This is the connected app consumerKey
var privateKey = require('fs').readFileSync('./privateKey.key', 'utf8');

jwtflow.getToken(clientId, privateKey, 'user@toImpersonate.com', function(err, accessToken) {
	// err
	// accessToken will contain the token to use on SalesForce API.
});

This is an example on how to use it with jsforce.

var jsforce = require('jsforce');
var jwtflow = require('salesforce-jwt');

var clientId = '3MVG9A2kN3Bn17hvVNDOE5FX8c9hS...30dgSSfyGi1FS09Zg'; // This is the connected app consumerKey
var privateKey = require('fs').readFileSync('./privateKey.key', 'utf8');
var instanceUrl = 'https://na15.salesforce.com'

jwtflow.getToken(clientId, privateKey, 'user@toImpersonate.com', function(err, accessToken) {
	// err

	var sfConnection = new jsforce.Connection();

    sfConnection.initialize({
      instanceUrl: instanceUrl,
      accessToken: accessToken
    });

});

License

MIT

About

SalesForce Auth 2.0 JWT Bearer Token Flow Implementation for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages