zsgogo/otpless-auth-sdk

SDK for Backend PHP SDK for resolving idToken and more.

v0.0.2 2023-12-01 09:14 UTC

This package is auto-updated.

Last update: 2024-04-30 00:33:17 UTC


README

A. OTPLessAuth Dependency

install Below dependency in your project's

composer require otpless/otpless-auth-sdk

you can also get latest version of dependency at https://packagist.org/packages/otpless/otpless-auth-sdk

B. OTPLessAuth class

The OtplessAuth class provides methods to integrate OTPLess authentication into your PHP backend application. This documentation explains the usage of the class and its methods.

Methods:

1. decodeIdToken

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:
decodeIdToken(id_token, client_id, client_secret, audience=None)

Method Params:

Params Data type Mandatory Constraints Remarks
idToken String true idToken which is JWT token which you get from OTPLess by exchange code API
clientId String true Your OTPLess Client Id
clientSecret String true Your OTPLess Client Secret

Return

Return: Object Name: UserDetail

{'success': True, 'auth_time': 1697649943, 'phone_number': '+9193******', 'email': 'dev***@gmail.com', 'name': 'Devloper From OTP-less', 'country_code': '+91', 'national_phone_number': '9313******'}

2. 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:
verifyCode(code, client_id, client_secret)

Method Params:

Params Data type Mandatory Constraints Remarks
code String true code which you get from OTPLess
clientId String true Your OTPLess Client Id
clientSecret String true Your OTPLess Client Secret

Return

Return: Object Name: UserDetail

{'success': True, 'auth_time': 1697649943, 'phone_number': '+9193******', 'email': 'dev***@gmail.com', 'name': 'Devloper From OTP-less', 'country_code': '+91', 'national_phone_number': '9313******'}

3. 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:
verifyToken(token, client_id, client_secret)

Method Params:

Params Data type Mandatory Constraints Remarks
token String true token which you get from OTPLess
clientId String true Your OTPLess Client Id
clientSecret String true Your OTPLess Client Secret

Return

Return: Object Name: UserDetail

{'success': True, 'auth_time': 1697649943, 'phone_number': '+9193******', 'email': 'dev***@gmail.com', 'name': 'Devloper From OTP-less', 'country_code': '+91', 'national_phone_number': '9313******'}

4. Generate Magic link

The Authorization Endpoint initiates the authentication process by sending a magic link to the user's WhatsApp or email, based on the provided contact information. This link is used to verify the identity of the user. Upon the user's action on this link, they are redirected to the specified URI with an authorization code included in the redirection.

Method Signature:
generateMagicLink(mobile_number, email, client_id, client_secret,redirect_uri,channel)

Method Params:

Params Data type Mandatory Constraints Remarks
channel String false if no channel given WHATSAPP is chosen as default WHATSAPP/SMS
mobile_number String false At least one required The user's mobile number for authentication in the format: country code + number (e.g., 91XXXXXXXXXX)
email String false At least one required The user's email address for authentication.
redirect_uri String true The URL to which the user will be redirected after authentication. This should be URL-encoded
clientId String true Your OTPLess Client Id
clientSecret String true Your OTPLess Client Secret

Return

Return: Object Name: RquestIds

{"requestIds":[{"type":"MOBILE","value":"ac48690347c24c0b8b54270590392b2a"}],"success":true}

Example of usage

require '../vendor/autoload.php';

use Otpless\OTPLessAuth; 

// Your ID token to decode
$token = 'your token here';

$clientId = 'your client id here';
$clientSecret = 'your client secret here';
// Initialize the library class
$auth = new OtplessAuth(); 


$auth->verifyToken($token,$clientId,$clientSecret);