1.0.8 • Published 4 months ago

otpless-node-js-auth-sdk v1.0.8

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

Merchant Integration Documentation(Backend Node JS Auth SDK)


A. OTPLessAuth Dependency

You can install the OTPLessAuth SDK using npm:

npm install otpless-node-js-auth-sdk

B. OTPLessAuth class

The OTPLessAuth Node.js SDK is a powerful library that enables you to perform authentication using the OTPLess service. This SDK simplifies the integration of OTPLess authentication into your Node.js applications.

Methods:


1. Verify Auth Token

This method help to resolve token which is issued by OTPLess which return user detail from that token also this method verify that token is valid, token should not expired and issued by only otpless.com

Method Signature:
const userDetail = await UserDetail.verifyToken(token, clientId, clientSecret);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
tokenStringtruetoken which you get from OTPLess
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

Return: Object Name: UserDetail


2. Decode IdToken

This method help to resolve idToken(JWT token) which is issued by OTPLess which return user detail from that token also this method verify that token is valid, token should not expired and issued by only otpless.com

Method Signature:
const userDetail = await UserDetail.decodeIdToken(idToken, clientId, clientSecret)

Method Params:

ParamsData typeMandatoryConstraintsRemarks
idTokenStringtrueidToken which is JWT token which you get from OTPLess by exchange code API
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

Return: Object Name: UserDetail


3. Verify Code

This method help to resolve code which is return from OTPLess which will return user detail from that code also this method verify that code is valid, code should not expired and issued by only otpless.com

Method Signature:
const userDetail = await UserDetail.verifyCode(code, clientId, clientSecret);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
codeStringtruecode which you get from OTPLess
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

Return: Object Name: UserDetail


4. Magic Link

This method help to get magic link which is return from OTPLess which will return token and request id from that mobile number or email id. Issued by only otpless.com

Method Signature:
const magicLinkTokens = await UserDetail.magicLink(
  mobile,
  email,
  redirectURI,
  channel,
  clientId,
  clientSecret
);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
mobileStringfalseInput by your user.
emailStringfalseInput by your user.
redirectURIStringtrueYour redirectURI.
channelStringfalseWHATSAPP/SMS (if no channel given WHATSAPP is chosen as default)
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

Return: Object Name: magicLinkTokens


5. Send OTP

This method help to send OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await UserDetail.sendOTP(phoneNumber, email, channel, hash, orderId, expiry, otpLength, clientId, clientSecret);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
phoneNumberStringtrueMobile Number of your users
emailStringtrueMail Id of your users
channelStringfalseWHATSAPP, SMS
hashStringtrueYour mobile application Hash
orderIdStringtrueUnique Order id
expiryIntfalseOTP expiry in sec
otpLengthStringfalseValues like 6 or 4
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

success (boolean): This will be true in case of method successfully performed operation. errorMessage (String): The will be errorMessage in case of any error. orderId (String): This will be your Unique Order id. refId (String): The will be refId when OTP successfully send.


6. ReSend OTP

This method help to resend OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await UserDetail.resendOTP(orderId, clientId, clientSecret);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
orderIdStringtrueUnique Order id(same as send method)
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

success (boolean): This will be true in case of method successfully performed operation. errorMessage (String): The will be errorMessage in case of any error. orderId (String): This will be your Unique Order id. refId (String): The will be refId when OTP successfully send.


7. Verify OTP

This method help to Verify OTP to your users and OTP issued by only otpless.com

Method Signature:
const response = await UserDetail.verifyOTP(email, phoneNumber, orderId, otp, clientId, clientSecret);

Method Params:

ParamsData typeMandatoryConstraintsRemarks
emailStringtrueMail Id of your users
phoneNumberStringtrueMobile Number of your users
orderIdStringtrueUnique Order id
otpStringtrueEnter otp here
clientIdStringtrueYour OTPLess Client Id
clientSecretStringtrueYour OTPLess Client Secret

Return

isOTPVerified (boolean): This will be true in case of OTP verified. reason (String): The will be errorMessage in case of OTP doesn't verified.


UserDetail Object Fields:

success (boolean): This will be true in case of method successfully performed operation. authTime (Long, required): The time when authentication was completed. phoneNumber (String, required): The user's phone number. countryCode (String, required): The country code of user's phone number. nationalPhoneNumber (String, required): The user's phone number without country code. email (String, required): The user's email address. name (String, required): The user's full name.

MagicLinkTokens Object Fields:

success (boolean): This will be true in case of method successfully performed operation. requestIds (List, required): List of Token and Type of AUth. type (String, required): Auth type. value (String, required): Token value.

Error case:

success (boolean): This will be false. The method is failed to perform. errorMessage (String): The message contains error information.

Example of usage

const { UserDetail } = require('otpless-node-js-auth-sdk');

const idToken = "..."; // Replace with your ID token
const clientId = "..."; // Replace with your client ID
const clientSecret = "..."; // Replace with your client secret

const userDetail = await UserDetail.decodeIdToken(
  idToken,
  clientId,
  clientSecret
);
console.log("User Details:", userDetail);

This method allows you to decode and verify OTPLess tokens and retrieve user information for integration into your node js application.

1.0.8

4 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago