# @cesarbr/knot-cloud-sdk-js-authenticator

> KNoT Cloud Authenticator library for NodeJS and browser

Latest version **2.2.0** (published 2021-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cesarbr/knot-cloud-sdk-js-authenticator
pnpm add @cesarbr/knot-cloud-sdk-js-authenticator
yarn add @cesarbr/knot-cloud-sdk-js-authenticator
bun add @cesarbr/knot-cloud-sdk-js-authenticator
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2021-05-27 |
| First published | 2019-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=6 |
| Dependencies | 1 |
| Unpacked size | 67.9 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | KNoT |
| Maintainers | rodrigoperazzo, ramonhpr, jneto, felipeborgiani, brunolimawd |

## Links

- npm: https://www.npmjs.com/package/@cesarbr/knot-cloud-sdk-js-authenticator
- Repository: https://github.com/CESARBR/knot-cloud-sdk-js-authenticator
- Homepage: https://github.com/CESARBR/knot-cloud-sdk-js-authenticator#readme
- Issues: https://github.com/CESARBR/knot-cloud-sdk-js-authenticator/issues
- npm.io page: https://npm.io/package/@cesarbr/knot-cloud-sdk-js-authenticator

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Recent versions

- 2.2.0 (latest) — 2021-05-27
- 2.1.2 — 2021-01-18
- 2.1.1 — 2020-07-24
- 2.1.0 — 2020-06-12
- 2.0.1 — 2020-05-18
- 2.0.0 — 2020-04-17
- 1.0.0 — 2019-07-05

## README

# knot-cloud-sdk-js-authenticator

KNoT Cloud authenticator service JavaScript library.

## Quickstart

### Install

```console
npm install --save @cesarbr/knot-cloud-sdk-js-authenticator
```

### Run

`KNoTCloudAuthenticator` connects to &lt;protocol&gt;://&lt;hostname&gt;:&lt;port&gt; using email and password as credentials. Replace this address with your authenticator instance and the credentials with valid ones.

```javascript
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");

const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});

async function main() {
  try {
    const user = await client.createUser(
      "awesome@email.com",
      "strong-password"
    );
    console.log(user);
    const token = client.createToken("awesome@email.com", "strong-password");
    console.log(token);
  } catch (err) {
    console.error(err);
  }
}
main();
```

## Methods

### Constructor(options)

Create a client object that will connect to a KNoT Cloud protocol authenticator instance.

#### Arguments

- `config` **Object** JSON object with request details.
  - `protocol` **String** (Optional) Either `'http'` or `'https'`. Default: `'https'`.
  - `hostname` **String** KNoT Cloud authenticator instance hostname. Default `'api.knot.cloud'`.
  - `port` **Number** (Optional) KNoT Cloud authenticator instance port. Default: 80/443.

#### Example

```javascript
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");

const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});
```

### createUser(email, password) &lt;Object&gt;

Creates a new user.

#### Arguments

- `email` **String** User email.
- `password` **String** User password in plain text.

#### Result

- `user` **Object** JSON object containing the created user's credentials.

#### Example

```javascript
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");

const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});

async function main() {
  try {
    const user = await client.createUser(
      "awesome@email.com",
      "strong-password"
    );
  } catch (err) {
    console.error(err);
  }
}
main();

// {
//  email: 'awesome@email.com',
//  password: 'strong-password',
// }
```

### createToken(email, password): &lt;Object&gt;

Generates a new access token for the user.

#### Arguments

- `email` **String** User email.
- `password` **String** User password, in plain text.

#### Result

- `token` **Object** JSON object containing the user's new access token.

#### Example

```javascript
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");

const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});

async function main() {
  try {
    const token = await client.createToken(
      "awesome@email.com",
      "strong-password"
    );
    console.log(token);
  } catch (err) {
    console.error(err);
  }
}
main();

// {
//  token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODcxMjkzNzIsImlhdCI6MTU4NzA5MzM3MiwiaXNzIjoibWFpbmZsdXguYXV0aG4iLCJzdWIiOiJkYWRhdmR2YkBrbm90LmNvbSIsInR5cGUiOjB9._lbRa2fzI_CvEorbEACVAf2UnHvkiCOORY55wCWUGAs'
// }
```

### createSession(token): &lt;Object&gt;

Generates a new session ID for the user, which will be used to receive thing's data.

#### Arguments

- `token` **String** User or application token.

#### Result

- `session` **Object** JSON object containing the user's new session ID.
  - `id` **String** user session ID.

#### Example

```javascript
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");

const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});

async function main() {
  try {
    const { token } = await client.createToken(
      "awesome@email.com",
      "strong-password"
    );
    const session = await client.createSession(token);
    console.log(session);
  } catch (err) {
    console.error(err);
  }
}
main();

// {
//   "id": "1t4izjcdHSYxfEZ9DUWMNewtlpR"
// }
```

---
_Source: https://npm.io/package/@cesarbr/knot-cloud-sdk-js-authenticator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
