# knox-token-library-js

> This library provides utility methods to generate and sign Knox Tokens using server side Javascript. The pre-requisites for using this utility are

Latest version **1.0.22** (published 2019-12-06) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install knox-token-library-js
pnpm add knox-token-library-js
yarn add knox-token-library-js
bun add knox-token-library-js
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.22 |
| Published | 2019-12-06 |
| First published | 2019-01-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | a.francisco, k.nagraj, pallavi.n |

## Links

- npm: https://www.npmjs.com/package/knox-token-library-js
- npm.io page: https://npm.io/package/knox-token-library-js

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [rsa-key](https://npm.io/package/rsa-key.md) 0.0.6
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.4.0

## Recent versions

- 1.0.22 (latest) — 2019-12-06
- 1.0.21 — 2019-02-07
- 1.0.20 — 2019-02-06
- 1.0.19 — 2019-02-02
- 1.0.18 — 2019-02-02
- 1.0.17 — 2019-02-01
- 1.0.16 — 2019-02-01
- 1.0.15 — 2019-02-01
- 1.0.14 — 2019-02-01
- 1.0.13 — 2019-02-01
- 1.0.12 — 2019-02-01
- 1.0.11 — 2019-01-31
- 1.0.10 — 2019-01-31
- 1.0.9 — 2019-01-31
- 1.0.8 — 2019-01-31
- … 8 more at https://npm.io/package/knox-token-library-js/versions

## README

This library provides utility methods to generate and sign Knox Tokens using server side Javascript. The pre-requisites for using this utility are

  - You have downloaded the Knox Certificate file (certificate.json)
  - You have generated a Client Identifier (api-key) for accessing apis of Knox Cloud Services.

# Intended Use
The workflow for making api calls to Knox Cloud Services is divided into a portal workflow, and a programmatic workflow.

### Portal flow
 1. Download Certificate from Knox Api Portal
 2. Generate and Download ClientIdentifier (api-key) for a specific Knox Solution

### Programmatic flow
3. Call Knox api to generate an Api Access Token. This api call requires a **signed ClientIdentifier**, and specific contents of your Certificate (Public Key).
4. Call Knox api for your intended workflow (eg: upload device, configure device etc). This api call requires your **signed Api Access Token**, and specific contents of your Certificate (Public Key).

This utility js library helps generate signed clientIdentifiers, and signed accessTokens.

### Install using npm
npm install knox-token-library-js

### Generate Signed ClientIdentifier

The following method is provided to generate a **signed client identifier**.
```
const knoxTokenLibraryJs = require('knox-token-library-js');
var signedClientId = knoxTokenLibraryJs.generateSignedClientIdentifierJWT("certificate.json", "my-client-identifier");
```
Input parameters:
- certificate: An input stream of the Knox certificate (certificate.json) that was downloaded from Knox Api portal.
- clientIdentifier: The string ClientIdentifier downloaded from Knox Api portal.

Output:
- A String representing the ClientIdentifier signed with the primary key from the downloaded Certificate.

### Generate Signed Api Access Token

KnoxTokenUtility class provides the following method to generate a **signed api access token**.
```
const knoxTokenLibraryJs = require('knox-token-library-js');
var signedAccessToken = knoxTokenLibraryJs.generateSignedAccessTokenJWT("certificate.json", "my-access-token");
```
Input parameters:
- certificate: An input stream of the Knox certificate (certificate.json) that was downloaded from Knox Api portal.
- accessToken: The string api AccessToken returned by calling Knox Cloud Services' generateAccessToken api.

Output:
- A String representing the AccessToken signed with the primary key from the downloaded Certificate.

License
----

Apache

---
_Source: https://npm.io/package/knox-token-library-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
