Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

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

2.1.1 • Public • Published

knot-cloud-sdk-js-authenticator

KNoT Cloud authenticator service JavaScript library.

Quickstart

Install

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

Run

KNoTCloudAuthenticator connects to <protocol>://<hostname>:<port> using email and password as credentials. Replace this address with your authenticator instance and the credentials with valid ones.

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

const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
 
const client = new KNoTCloudAuthenticator({
  protocol: "https",
  hostname: "api.knot.cloud",
  port: 443,
});

createUser(email, password) <Object>

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

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): <Object>

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

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'
// }

Keywords

none

Install

npm i @cesarbr/knot-cloud-sdk-js-authenticator

DownloadsWeekly Downloads

15

Version

2.1.1

License

MIT

Unpacked Size

65.3 kB

Total Files

16

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar