Coder Social home page Coder Social logo

esdrasjnr / knot-cloud-sdk-js-authenticator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cesarbr/knot-cloud-sdk-js-authenticator

0.0 1.0 0.0 204 KB

KNoT Cloud authenticator service JavaScript library

License: MIT License

JavaScript 100.00%

knot-cloud-sdk-js-authenticator's Introduction

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(
      "[email protected]",
      "strong-password"
    );
    console.log(user);
    const token = client.createToken("[email protected]", "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(
      "[email protected]",
      "strong-password"
    );
  } catch (err) {
    console.error(err);
  }
}
main();

// {
//  email: '[email protected]',
//  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(
      "[email protected]",
      "strong-password"
    );
    console.log(token);
  } catch (err) {
    console.error(err);
  }
}
main();

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

knot-cloud-sdk-js-authenticator's People

Contributors

figueredo avatar lcbm avatar ramonhpr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.