Minimal implementation of the Salesforce OAuth 2.0 JWT Bearer Token Flow for server-to-server authentication. Version 1.1.0 is the current stable release with no recent updates (low maintenance cadence). Enables impersonating users via a connected app's private key and consumer key. Key differentiator: lightweight (no heavy SDK) and designed to integrate with jsforce by returning access_token and instance_url. No breaking changes reported; simple callback-based API.
npm install node-salesforce-jwtVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to obtain a JWT bearer token using a private key and connected app credentials, then use it with jsforce to query Salesforce.
Set isTest: true for sandbox/test instances, false for production. This is not automatically detected.
Ensure privateKey is a string: fs.readFileSync('./key.pem', 'utf8')Use the Consumer Key (long string ending with .something) from your Salesforce Connected App definition.
Set environment variable NODE_TLS_REJECT_UNAUTHORIZED=0 (not recommended) or update Node.js CA certificate bundle.
Verify the clientId is the Consumer Key from the connected app (not the Consumer Secret) and that the app is properly configured with the correct OAuth scopes.
Ensure the private key file is correctly formatted with BEGIN and END RSA PRIVATE KEY lines. Read file with utf8 encoding.