1.0.1 • Published 6 years ago

blockauth-client v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

What?

  • Javascript library.
  • Interacts with BlockAuth server.
  • Create a new login attempt.
  • Check if an attempt has been successful.

Setup

Before using the library, please read the whitepaper and check out the demo to get an understanding of how BlockAuth works.

Then install the library:

npm install --save blockauth-client

Usage

The library can carry out two operations:

  1. Create a new login attempt.
  2. Verify that the login attempt has been successful.

Both of these actions will send HTTP requests to the API provided by the BlockAuth server.

Creating a Login Attempt

import BlockAuth from 'blockauth-client';

BlockAuth.createContract(serverURI, address, (contract, error) => {
  if (error) {
    // An error occured!
  }
  console.log(contract);
});

This function expects:

  • serverURI - full URI of your BlockAuth server.
  • address - NEO public address of user.
  • callback - function that will be called when the action has completed.

The callback function will handed:

  • contract - object holding data about the new login attempt.
  • error - boolean stating if there was an error.

The contract object has a number of fields:

  • address - smart contract address.
  • expiresAt - UNIX timestamp of when the login attempt will expire.
  • parameters - array of UUIDs that are to be used by the user when invoking the smart contract.
  • token - JWT token for checking if the login attempt was successful.

Display the contract address and parameters to the user, and ask them to invoke the smart contract before the login attempt expires.

Verifying a Login Attempt

import BlockAuth from 'blockauth-client';

BlockAuth.checkInvoke(serverURI, token, (data, error) => {
  if (error) {
    // An error occured!
  }
  console.log(data);
});

This function expects:

  • serverURI - full URI of your BlockAuth server.
  • token - JWT token returned when creating the login attempt.
  • callback - function that will be called when the action has completed.

The callback function will handed:

  • data - object holding data about if a successful login attempt.
  • error - boolean stating if there was an error.

The data object has a number of fields:

  • token - JWT token to be used for logged in experience.
  • transactionHash - NEO transaction hash of the users smart contract invocation.

Regularly call this function until either the login attempt was successful or it expires.

On success, you are handed a JWT token which you should store in the browser, and use to prove the identity of the user when they carry out actions on your website.


1.0.1

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago