This package is for generating OTP with the provider handling the validity and storage of the OTP. This is developed as for a study with the use of QR code with OTPs for improved security. For any questions and suggestions feel free to send an email to alidejandoandrada@gmail.com.
npm install paperstack
or
yarn add paperstack
const paperstack = require('paperstack')
Avoid storing your credentials directly in variable. We recommend storing them in the ENV and access them through process.ENV.variable_name
Create a separate file to for the package initialization and call init().
const paperstack = require('paperstack')
const client = new paperstack(email, password, clientSecret, clientID)
client.init()
module.exports = client
A simple OTP schema with the OTP in QR option.
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
uniqueId | string | true | A unique ID which will be used later as reference for verification of OTP |
This will return an object containing the OTP and a base64 string that can be rendered to an image which contains the raw OTP.
client.upsertUser(uniqueID)
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
id | string | true | A unique ID for a valid generator | |
OTP | string | true | OTP user input |
OTP verification. Returns a bool. This can be used with either of the 2 schemas
client.verifyOTP(id, otp)
OTP schema where the user can generate OTP for himself/herself when logging in. Generator is valid for a limited amount of time generation can only be allowed by the developer(Ideally called upon login attempt).
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
id | string | true | A unique ID which will be used later as reference for verification of OTP | |
expiry | number | true | Duration of the OTP generator validity in seconds(Roughly 86400 seconds a day). |
Creates an OTP generator. Returns a link that is valid within the Expiry's duration. It is advised for the user to save the QR code instead of the link.
client.createOTPGenerator(id, expiry)
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
id | string | true | A unique ID for a valid generator |
Allows the valid generator to generate OTPs using the generator link. Valid for only 5 minutes
client.allowGenerateOTP(id)
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
id | string | true | A unique ID used earlier to generate and OTP or create a Generator |
Returns an object contaning the current status and details linked to an ID.
client.checkUserStatus(id)