@cesarbr/knot-cloud-sdk-js-authenticator
KNoT Cloud Authenticator library for NodeJS and browser
Last updated 2 months ago by jneto .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @cesarbr/knot-cloud-sdk-js-authenticator 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.1.0                                ...           latest (2 months ago)

4 Versions

  • 2.1.0                                ...           2 months ago
  • 2.0.1                                ...           3 months ago
  • 2.0.0                                ...           4 months ago
  • 1.0.0                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)

Copyright 2014 - 2016 © taobao.org |