# salesforce-jwt-bearer-token-flow

> SalesForce OAuth 2.0 JWT Bearer Token Flow Implementation

Latest version **0.2.4** (published 2020-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install salesforce-jwt-bearer-token-flow
pnpm add salesforce-jwt-bearer-token-flow
yarn add salesforce-jwt-bearer-token-flow
bun add salesforce-jwt-bearer-token-flow
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2020-02-24 |
| First published | 2018-01-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 3 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Arthur IMIRZIAN |
| Maintainers | arthur.imirzian |
| Keywords | Salesforce, JWT, OAuth |

## Links

- npm: https://www.npmjs.com/package/salesforce-jwt-bearer-token-flow
- Repository: https://github.com/arthurimirzian/salesforce-jwt-bearer-token-flow
- Homepage: https://github.com/arthurimirzian/salesforce-jwt-bearer-token-flow#readme
- Issues: https://github.com/arthurimirzian/salesforce-jwt-bearer-token-flow/issues
- npm.io page: https://npm.io/package/salesforce-jwt-bearer-token-flow

## Dependencies (3)

- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [request](https://npm.io/package/request.md) ^2.88.2
- [base64url](https://npm.io/package/base64url.md) ^3.0.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 0.2.4 (latest) — 2020-02-24
- 0.2.3 — 2019-06-24
- 0.2.2 — 2018-08-28
- 0.2.1 — 2018-05-30
- 0.2.0 — 2018-05-23
- 0.1.8 — 2018-05-10
- 0.1.7 — 2018-01-09
- 0.1.6 — 2018-01-09
- 0.1.5 — 2018-01-09
- 0.1.4 — 2018-01-09
- 0.1.3 — 2018-01-09
- 0.1.2 — 2018-01-09
- 0.1.1 — 2018-01-09
- 0.1.0 — 2018-01-08

## README

# Salesforce OAuth 2.0 JWT Bearer Token Flow Implementation
[Salesforce OAuth 2.0 JWT Bearer Token Flow](https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5)

## Installation
```bash
$ npm install salesforce-jwt-bearer-token-flow --save
```

## Salesforce Configuration

### Step 1 : The certificate
Create the private key and the certificate in osx terminal:
```bash
$ openssl req  -nodes -new -x509  -keyout private.pem -out server.cert
```

### Step 2 : The connected App
Create a connected app in Salesforce:

1. Select **Enable OAuth Settings**
2. Select **Use digital signatures**
3. Upload the generated **certificate**

## Usage

### Input
```javascript
const   fs = require('fs')
    ,   privateKey = fs.readFileSync('private.pem').toString('utf8')
    ,   jwt = require("salesforce-jwt-bearer-token-flow")
;

var token = jwt.getToken({
        iss: "<YOUR_CONNECTED_APP_CLIENT_ID>",
        sub: "<YOUR_SALESFORCE_USERNAME>",
        aud: "<YOUR_AUDIENCE>",
        privateKey: privateKey
    },
    function(err, token){
        console.log(token);
    }
);
```
The audience (aud) must be:
- https://login.salesforce.com,
- https://test.salesforce.com
- https://acme.force.com/customers (where acme.force.com/customers is your community URL)

### Output

```javascript
{
    access_token: 'xxxxxxxxxx!ARYAQNzk4LCbHsX[...]',
    scope: 'id full',
    instance_url: 'https://eu6.salesforce.com',
    id: 'https://login.salesforce.com/id/xxxxxxxxxxEAI/yyyyyyyyyy',
    token_type: 'Bearer'
}
```

## License

MIT

---
_Source: https://npm.io/package/salesforce-jwt-bearer-token-flow · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
