You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

salesforce-jwt-promise

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

salesforce-jwt-promise

Promise Based SalesForce Auth 2.0 JWT Bearer Token Flow Implementation, written in typescript

0.1.8
latest
Source
npmnpm
Version published
Weekly downloads
294
19.03%
Maintainers
1
Weekly downloads
 
Created
Source

salesforce-jwt-promise

npm version

Promise Based implementation of OAuth 2.0 JWT Bearer Token Flow.

  • written in typescript
  • returns Promise to support async/await syntax.
  • Compatible with jsforce and any other clients.

Installation

$ npm install salesforce-jwt-promise

Usage

This library contains an single export: getJWTToken() which accepts an object with the following options object parameter:

  • clientId: The salesforce connected app consumerKey
  • privateKey: The private key used to sign the certificated uploaded to the connected app
  • userName: The user to impersonate
  • audience: (Optional) Defaults to https://login.salesforce.com
  • instance_url: (Optional) Defaults to audience

A success response will include the following properties:

  • access_token
  • scope
  • instance_url
  • id
  • token_type

import { getJWTToken } from 'salesforce-jwt-promise';

var clientId = '3MVG9A2kN3Bn17hvVNDOE5FX8c9hS...30dgSSfyGi1FS09Zg';
var privateKey = require('fs').readFileSync('./privateKey.key', 'utf8'); // this should probably be encrypted!

try{
let jwtResp = await getJWTToken(
    {
        clientId: clientId,
        privateKey: privateKey,
        userName: 'user@toImpersonate.com',
        audience: 'https://test.salesforce.com'
    }
);

//use token
var sfConnection = new jsforce.Connection();

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

}catch(e){
    console.log(e);
}

License

MIT

Forked from leandrob/node-salesforce-jwt

Keywords

Salesforce

FAQs

Package last updated on 18 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts