Skip to content
Docs

References / SDKs

PHP

To add the sdk in your PHP project you can download or pull the mojoauth php-sdk from the github repo, and configure it using your MojoAuth API KEY.

php
<?php
require_once(__DIR__."/src/mojoAuthAPI.php");
// Get your MojoAuth API Key from MojoAuth Dashboard
$mojoauth = new mojoAuthAPI("Your MojoAuth API Key");

Add the calling of the sendLinkOnEmail() function and pass the Email and optional query parameters to send the magiclink.

php
$email = "Your Email";
$language = "Your language";
$redirect_url = "Your redirect URL";
$response = $mojoauth->sendLinkOnEmail($email, $language, $redirect_url);
var_dump($response);

Add the calling of the checkLoginStatus() function and pass the state id received from the sendLinkOnEmail() function.

php
$state_id = "Your StateID";
$response = $mojoauth->checkLoginStatus($state_id);
var_dump($response);

Add the calling of the resendMagicLink() function and pass the state id received from the sendLinkOnEmail() function.

php
$state_id = "Your StateID";
$language = "Your language";
$redirect_url = "Your redirect URL";
$response = $mojoauth->resendMagicLink($state_id, $language, $redirect_url);
var_dump($response);

Add the calling of the sendEmailOTP() function and pass the Email and optional query parameters to send the OTP.

php
$email = "Your Email";
$language = "Your language";
$response = $mojoauth->sendEmailOTP($email, $language);
var_dump($response);

Add the calling of the verifyEmailOTP() function and pass the OTP and state id received from the sendEmailOTP() function.

php
$state_id = "Your StateID"
$otp = "Your OTP"
$response = $mojoauth->verifyEmailOTP($state_id, $otp);
var_dump($response);

Add the calling of the resendEmailOTP() function and pass the state id received from the sendEmailOTP() function.

php
$state_id = "Your StateID";
$language = "Your language";
$response = $mojoauth->resendEmailOTP($state_id, $language);
var_dump($response);

Add the calling of the sendPhoneOTP() function and pass the phone number and optional query parameters to send the OTP.

php
$phone = "Your Phone" // pass the phone number in the international format e.g for US, +1XXXXXXXXXX
$language = "Your language"
$response = $mojoauth->sendPhoneOTP($email, $language);
var_dump($response);

Add the calling of the verifyPhoneOTP() function and pass the OTP and state id received from the sendPhoneOTP() function.

php
$state_id = "Your StateID"
$otp = "Your OTP"
$response = $mojoauth->verifyPhoneOTP($state_id, $otp);
var_dump($response);

Add the calling of the resendPhoneOTP() function and pass the state id received from the sendPhoneOTP() function.

php
$state_id = "Your StateID";
$language = "Your language";
$response = $mojoauth->resendPhoneOTP($state_id, $language);
var_dump($response);

Use the MojoAuth getUserProfileData() Method to get User Profile Data from MojoAuth JWT token.

php
//Step 1 Get Public Key / Certificate from MojoAuth Server
$result = $mojoauth->getPublicKey();
$publicKey = json_decode($result['response']);
//Step 2 Pass JWT token and publickey to verify user
$userProfileData = $mojoauth->getUserProfileData($access_token, $publicKey->data)