psylence303 / sf-jwt-generator

Generate JWT for the SalesForce OAuth endpoint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SalesForce JWT generator

Generates a JWT using the provided config. Then it's your part to use this JWT to retrieve the actual token from SF OAuth.

Installation

yarn

Configuration

The configuration has the following properties (all of them except the offsetInMs are mandatory):

const config = {
    clientId: '<YOUR CLIENT ID HERE>',
    offsetInMs: '<HOW MANY MILLISECONDS THE TOKEN IS VALID (OPTIONAL, DEFAULT IS 1 DAY)',
    privateKey: '<YOUR PRIVATE KEY AS UTF-8 STRING>',
    url: '<SALESFORCE BASE URL>',
    username: '<YOUR SALESFORCE USERNAME>'
}

The url should be one of:

https://login.salesforce.com
https://test.salesforce.com

Usage

import {generateJwt} from 'sf-jwt-generator';

const jwt = generateJwt(config); // the config provided above

To import the config type definition in TypeScript:

import {ConnectionConfig} from 'sf-jwt-generator';

const config:ConnectionConfig = {
    // config here
}

About

Generate JWT for the SalesForce OAuth endpoint


Languages

Language:TypeScript 93.8%Language:JavaScript 6.2%