Privacy-First, Secure Authentication
1. PHP sample code
This PHP code runs on your server to securely communicate with Jekimo.
It sends the user’s temporary token, receives the verification status (OK, KO, or pending),
and obtains the link or QR code to display to the user—without ever exposing your API key in the browser.
// your-website-url/jekimo-check.php
<?php
$token = $_POST['token'] ?? '';
$apiKey = 'YOUR_SECRET_API_KEY';
$ch = curl_init("https://www.jekimo.com/app.php/v1.1/auth/check");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"X-API-KEY: $apiKey",
"token: $token",
"Content-Type: application/x-www-form-urlencoded"
]);
$response = curl_exec($ch);
curl_close($ch);
header('Content-Type: application/json');
echo $response;
?>
2. Javascript sample code
This JavaScript runs in the browser and continuously checks the user’s verification status by calling the PHP script on your server.
It polls the server at intervals: if the response is "OK", the user is redirected to the protected page;
if "KO", access is denied; if "created", it waits and checks again.
This loop ensures the site responds immediately once the user completes the Jekimo verification on their device.
// JavaScript code to run on the page displaying the QR code or verification link
async function pollJekimo(token, attempt = 1) {
const maxAttempts = 24; // 24 calls max ~ 120 seconds
try {
const res = await fetch('your-website-url/jekimo-check.php', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: `token=${encodeURIComponent(token)}`
});
const data = await res.json();
if (data.status === "OK") {
window.location.href = '/dashboard';
} else if (data.status === "KO") {
alert("Access denied: authentication failed.");
} else if (data.status === "created" && attempt < maxAttempts) {
setTimeout(() => pollJekimo(token, attempt + 1), 5000); // 5 seconds interval
} else if (attempt >= maxAttempts) {
alert("Verification timeout. Please try again.");
}
} catch (err) {
console.error(err);
if (attempt < maxAttempts) {
setTimeout(() => pollJekimo(token, attempt + 1), 5000);
} else {
alert("Verification timeout due to network error. Please try again.");
}
}
}
// start polling
pollJekimo('USER_TEMP_TOKEN_FROM_JEKIMO');