2.1.0 • Published 5 years ago

@haventec/authenticate-client-js v2.1.0

Weekly downloads
1
License
-
Repository
-
Last release
5 years ago

Haventec Authenticate client JS

A collection of javascript functions to facilitate client-side interaction with Haventec backend services.

Getting Started

Installation

npm install @haventec/authenticate-client-js

Getting Started

Start by importing the HaventecAuthenticateClient (For Angular 2+ see "Angular 2+ Setup" below)

import { HaventecAuthenticateClient } from '@haventec/authenticate-client-js;

let haventecAuthenticateClient = new HaventecAuthenticateClient();

Initiate your Application and set the domain of your backend server. You can get your Application UUID from registering an Organisation at https://console.haventec.com and adding a new application.

initialize('https://my-backend-server.com', '1111-1111-1111-1111-1111-1111');

Sign up a user.

signUp('NewUser', 'newuser@somedomain.com').then(
      data => {
          // User was successfully signed up
      },
      err => {
          // Something when wrong
      }
   );

Log the user in

login('NewUser', '1234').then(
      data => {
          // User has successfully logged in
      },
      err => {
          // Something when wrong
      }
    );

Log the user out

login().then(
     data => {
         // User has successfully logged out
     },
     err => {
         // Something when wrong
     }
   );

Angular 2+ Setup

For Angular 2+, HaventecAuthenticateClientProvider is provided to easily inject HaventecAuthenticateClient into your Module, simply add it to the providers array. It can then be injected into constructors as is typical.

import { HaventecAuthenticateClient, HaventecAuthenticateClientFactory } from '@haventec/authenticate-client-js';

...

providers: [
    { provide: HaventecAuthenticateClient, useFactory: HaventecAuthenticateClientFactory, deps: [ ] }
]

API

Initialise your application

This function initialises the client. It sets the domain of your backend server, and the application uuid. If your backend server is already configured with the applicationUuid, this is not necessary You can see your application uuid in the Haventec Console -> Applications -> Your application

initialize(domain: string, applicationUuid?: string)
ParameterRequiredDescription
domainYesYour backend server server domain (https://your-domain.com/some-path)
applicationUuidNoYour Haventec Authentication application uuid. For backend servers that act as proxy to Authenticate, this is not necessary

Activate device

Activate the user's recently added device.

activateDevice(username: string, pin: string, activationToken: string, urlOverwrite?:string)
ParameterRequiredDescription
usernameYesThe user's name, can be a real name, alias or email
pinYesThe user's PIN
activationTokenYesThe activation token send to the user in an out of band channel (email, push notification). This is controlled by the backend
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Add device

Add the user's current device.

addDevice(username: string, deviceName?: string, urlOverwrite?:string)
ParameterRequiredDescription
usernameYesThe user's name, can be a real name, alias or email
deviceNameNoThe name of the device being registered. If undefienced the client with auto generate the device name based on the OS, browser and hardware
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Activate user

activateUser(username:string, activationToken:string, pin:string, urlOverwrite?:string, deviceName?:string)
ParameterRequiredDescription
usernameYesThe user's name, can be a real name, alias or email
activationTokenYesThe activation token sent to the user in an out of band channel (email, push notification). This is controlled by the backend
pinYesThe user's PIN
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Delete device

deleteDevice(deviceUuid: string, urlOverwrite?:string)
ParameterRequiredDescription
deviceUuidYesThe uuid of the device you want to delete. The user must be the owner of the device to be able to delete it.
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Lock device

lockDevice(deviceUuid: string, urlOverwrite?:string)
ParameterRequiredDescription
deviceUuidYesThe uuid of the device you want to lock. The user must be the owner of the device to be able to lock it.
urlOverwriteNoOverwrite the deleteDevice backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Unlock device

unlockDevice(deviceUuid: string, urlOverwrite?:string)
ParameterRequiredDescription
deviceUuidYesThe uuid of the device you want to unlock. The user must be the owner of the device to be able to unlock it.
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Forgot PIN

Initiate a Forgot PIN request.

forgotPin(username: string, urlOverwrite?:string)
ParameterRequiredDescription
usernameYesThe user's username
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Get the current user details

getCurrentUserDetails(urlOverwrite?:string)
ParameterRequiredDescription
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Get a users devices

Get a list of device for a user.

getUserDevices(userUuid: string, urlOverwrite?:string)
ParameterRequiredDescription
userUuidYesThe user's uuid
urlOverwriteNoOverwrite the deleteDevice backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Login

login(username: string, pin: string, urlOverwrite?:string)
ParameterRequiredDescription
usernameYesThe user's username
pinYesThe user's PIN
urlOverwriteNoOverwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Logout

logout(urlOverwrite?:string)
ParameterRequiredDescription
urlOverwriteNoOverwrite the logout backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Reset PIN

Reset a PIN for a device. Each device has an independent PIN, resetting a PIN does not reset the user PIN across all of there devices, it only resets the PIN on the device that request the reset PIN.

resetPin(username: string, resetPinToken: string, pin:string, urlOverwrite?:string)
ParameterRequiredDescription
usernameYesThe user's username
resetPinTokenYesThe reset PIN token sent to the user in an out of band channel (email, push notification). This is controlled by the backend
pinYesThe user's PIN
urlOverwriteNoOverwrite the login backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain

Sign up a user

signUp(username: string, email: string, urlOverwrite?:string, mobileNumber?: string)
ParameterRequiredDescription
usernameYesThe user's username
emailYesThe user's email
pinYesThe user's PIN
urlOverwriteNoOverwrite the login backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain
mobileNumberNoThe user's mobile number

General-purpose Functions

isAdmin

Detects if the logged-in user is an Admin user

haventecAuthenticateClient.isAdmin(); 

purge

Removes all data for the current user - including localStorage

haventecAuthenticateClient.purge(); 

invalidateToken

Sets the token of the current user to undefined, so that no further calls can be made

haventecAuthenticateClient.invalidateToken(); 

getDeviceName

Get the device name of the current device

let deviceName = haventecAuthenticateClient.getDeviceName(); 

getUserUuid

Returns the Haventec userUuid unique ID representing the current authenticated user. Returns undefined if not authenticated

let userUuid = haventecAuthenticateClient.getUserUuid(); 

getApplicationUuid

Returns the Haventec applicationUuid unique ID representing the application of the current user. Returns undefined if there a user has not been provisioned on the current device

let applicationUuid = haventecAuthenticateClient.getApplicationUuid(); 

Build and Publish

This project uses npmextra Configuration options can be found here To build run the command

npmts
npm publish

Test build locally before publishing

Compile the code

npmts

Package the code (creates a file called haventec-common-js-x.x.x.tgz)

npm pack

Create a test npm project and add the package from above

mkdir test-haventec-common-js
cd test-haventec-common-js
npm init
npm install [path-to]/haventec-common-js-x.x.x.tgz

Now you can use Haventec's common-js in your new

Publish

npm publish

License

This code is available under the MIT license. A copy of the license can be found in the LICENSE file included with the distribution.

2.1.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago