npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@haventec/authenticate-client-js

v2.1.0

Published

Haventec Authenticate Client JS

Downloads

5

Readme

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', '[email protected]').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)

| Parameter | Required | Description | | ----- | ----- | ----- | | domain | Yes | Your backend server server domain (https://your-domain.com/some-path) | | applicationUuid | No | Your 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's name, can be a real name, alias or email| | pin | Yes | The user's PIN | | activationToken | Yes | The activation token send to the user in an out of band channel (email, push notification). This is controlled by the backend | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's name, can be a real name, alias or email| | deviceName | No | The name of the device being registered. If undefienced the client with auto generate the device name based on the OS, browser and hardware | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's name, can be a real name, alias or email| | activationToken | Yes | The activation token sent to the user in an out of band channel (email, push notification). This is controlled by the backend | | pin | Yes | The user's PIN | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | deviceUuid | Yes | The uuid of the device you want to delete. The user must be the owner of the device to be able to delete it.| | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | deviceUuid | Yes | The uuid of the device you want to lock. The user must be the owner of the device to be able to lock it.| | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | deviceUuid | Yes | The uuid of the device you want to unlock. The user must be the owner of the device to be able to unlock it.| | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's username | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | userUuid | Yes | The user's uuid | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's username | | pin | Yes | The user's PIN | | urlOverwrite | No | Overwrite the backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain|

Logout

logout(urlOverwrite?:string)

| Parameter | Required | Description | | ----- | ----- | ----- | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's username | | resetPinToken | Yes | The reset PIN token sent to the user in an out of band channel (email, push notification). This is controlled by the backend | | pin | Yes | The user's PIN | | urlOverwrite | No | Overwrite 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)

| Parameter | Required | Description | | ----- | ----- | ----- | | username | Yes | The user's username | | email | Yes | The user's email | | pin | Yes | The user's PIN | | urlOverwrite | No | Overwrite the login backend path URL, example '/my-custom-backend-path'. Note this overwrites the URL path not the domain| | mobileNumber | No | The 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.