Integrate OTP verification using mini orange API - PHP
How can I integrate MiniOrange OTP verification into a custom form, or does it have any API available for PHP?
MiniOrange provides a variety of solutions for two-factor authentication, including OTP (One-Time Password) verification. To integrate MiniOrange OTP verification into a custom form in PHP, you can use their APIs or SDKs. Here's a general guide to help you get started:
First, sign up for an account on the MiniOrange website and log in to your dashboard.
Navigate to the OTP Authentication section in your MiniOrange dashboard and enable OTP for your application.
You may need to obtain API credentials (such as API key and secret) from the MiniOrange dashboard to authenticate your requests.
Once you have the API credentials, you can integrate OTP verification into your custom PHP form. Here's a high-level overview:
a. Send User's Information:
b. Call MiniOrange API:
c. Handle API Response:
d. Display Result:
Use PHP's curl library or any HTTP library to make a request to MiniOrange's OTP verification API. Include the necessary parameters such as user details.
Process the response from MiniOrange's API to determine whether the OTP verification was successful or not.
Based on the API response, display an appropriate message to the user indicating whether the OTP verification succeeded or failed.
These two sets of instructions provide guidance on incorporating the miniOrange OTP Verification service into both your mobile device and computer through the utilization of PHP.
1. Get customerkey and apikey from your mini orange account https://login.xecurify.com/moas/login
2. Here's a simplified code
<?php function otpConnection($url,$jsonRequest) { $customerKey = "XXXXX"; //Get customerkey from mini orange account $apiKey = "XXXXX"; //Get apikey from mini orange account $currentTimeInMillis = round(microtime(true) * 1000); $stringToHash = $customerKey . number_format ( $currentTimeInMillis, 0, '', '' ) . $apiKey; $hashValue = hash("sha512", $stringToHash); $jsonRequestString = json_encode($jsonRequest); $customerKeyHeader = "Customer-Key: " . $customerKey; $timestampHeader = "Timestamp: " . number_format ( $currentTimeInMillis, 0, '', '' ); $authorizationHeader = "Authorization: " . $hashValue; /* Initialize curl */ $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", $customerKeyHeader,$timestampHeader, $authorizationHeader)); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_VERBOSE, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonRequestString); curl_setopt($ch, CURLOPT_POST, 1); /* Calling the rest API */ $result = curl_exec($ch); if (curl_errno($ch)) { echo curl_error($ch); } else { curl_close($ch); } /* If a valid response is received, get the JSON response */ $response = (array)json_decode($result); $status = $response['status']; if($status == 'SUCCESS') { return $response; } else { return "FAILED: " . $response['message']; } } /* Generate and send a OTP message to mobile phone */ $generateUrl = "https://login.xecurify.com/moas/api/auth/challenge"; //OTP Generation Endpoint $customerKey = "XXXX"; // Enter your customer key $mobile_number = "XXXXXX"; // Enter a valid mobile number (number should have country code ex:+91) $jsonRequest = array( "customerKey" => $customerKey, "phone" => $mobile_number, "authType" => "SMS", "transactionName" => "BUGGERSPOT-OTP-VERIFICATION", ); $send_otp = otpConnection($generateUrl,$jsonRequest); /* Check OTP status */ if(is_array($send_otp) && $send_otp['status'] == "SUCCESS") { // You have to pass the data to validation step so you can pass the data with help of form submission ?> <form> <label>Enter Your OTP</label> <!-- Enter Your OTP here --> <input type="text" name="otp"> <!-- Pass txID in hidden field --> <input type="hidden" name="txID" value="<?= $send_otp['txId']; ?>"> <input type="submit" name="submit"> </form> <?php /* Validate OTP */ if(isset($_POST['submit'])) { $validateUrl = "https://login.xecurify.com/moas/api/auth/validate"; //OTP Validation Endpoint $jsonRequest = array('txId' => $_POST['txId'], 'token' => $_POST['otp']); $validate_otp = otpConnection($validateUrl,$jsonRequest); if(is_array($validate_otp) && $validate_otp['status'] == "SUCCESS") { echo "Your OTP verified successfully"; } }