Giter Site home page Giter Site logo

netoax / 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 0.0 0.0 221 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: 'auth.knot.cloud',
});

async function main() {
  try {
    console.log(await client.authUser('[email protected]', '123qwe!@#QWE'));
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

Methods

constructor(options)

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

Arguments

  • options Object JSON object with request details.
    • protocol String (Optional) Either 'http' or 'https'. Default: 'https'.
    • hostname String KNoT Cloud authenticator instance host name.
    • port Number (Optional) KNoT Cloud authenticator instance port. Default: 443.
    • pathname String (Optional) Path name on the server.

Example

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

const client = new KNoTCloudAuthenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

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 user credentials after creation on cloud.

Example

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

const client = new KNoTCloudAuthenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

async function main() {
  try {
    console.log(await client.createUser('[email protected]', '123qwe!@#QWE'));
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

// { id: '863ad780-efd9-4158-b24a-026de3f1dffb'
//   token: '40ad864d503488eda9b629825876d46cb1356bdf' }

authUser(email, password): <Object>

Authenticate a user.

Arguments

  • email String User email.
  • password String User password in plain text.

Result

  • user Object JSON object containing user credentials after authentication on cloud.

Example

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

const client = new KNoTCloudAuthenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

async function main() {
  try {
    console.log(await client.authUser('[email protected]', '123qwe!@#QWE'));
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

// { id: '863ad780-efd9-4158-b24a-026de3f1dffb'
//   token: '40ad864d503488eda9b629825876d46cb1356bdf' }

forgotPassword(email): <Void>

Tells to cloud that a user forgot its password. The cloud then sends an email with a token to reset the password.

Arguments

  • email String User email.

Example

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

const client = new KNoTCloudAuthenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

async function main() {
  try {
    await client.forgotPassword('[email protected]');
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

resetPassword(email, token, newPassword): <Void>

Resets a password from a user.

Arguments

  • email String User email.
  • token String Token sent by email.
  • newPassword String User password in plain text.

Example

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

const client = new KNoTCloudAuthenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

async function main() {
  try {
    const token = '54ad864d5034887419b629825876d46cb1356b06';
    const newPassword = 'QWEqwe!@#123';
    await client.resetPassword('[email protected]', token, newPassword);
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

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.