Easily integrate Authentica's secure authentication (OTP, Face, Voice, SMS) into your Laravel app.
composer require authentica/authenticaphp artisan vendor:publish --tag=authentica-configOr publish all vendor configs:
php artisan vendor:publish --tag=configAdd the following to your .env file (see .env.example for all options):
AUTHENTICA_API_KEY=your_api_key_here
AUTHENTICA_BASE_URL=https://api.authentica.sa/api/v2
AUTHENTICA_DEFAULT_CHANNEL=sms # sms, whatsapp, email
AUTHENTICA_FALLBACK_CHANNEL=email # optional
AUTHENTICA_DEFAULT_TEMPLATE_ID=31 # optional, default: 1
AUTHENTICA_FALLBACK_TEMPLATE_ID=2 # optional, default: 2
AUTHENTICA_DEFAULT_SENDER_NAME=MyBrand # optional
AUTHENTICA_DEFAULT_EMAIL=your@email.com # optional
Import the facade at the top of your file:
use Authentica\LaravelAuthentica\Facades\Authentica;Authentica::sendOtp([
'phone' => '+966551234567',
'method' => 'sms',
'otp' => '123456', // Optional custom OTP
'fallback_email' => 'user@example.com', // Optional fallback
]);$result = Authentica::verifyOtp('123456', '+966551234567');
if ($result->successful()) {
// Authentication successful
}$result = Authentica::verifyFace(
'user_123',
Authentica::fileToBase64(storage_path('app/faces/reference.jpg')),
Authentica::fileToBase64(storage_path('app/faces/capture.jpg'))
);
if ($result->successful()) {
// Face match successful
} else {
// Handle failed verification
$error = $result->message();
}$result = Authentica::verifyVoice(
'user_123',
Authentica::fileToBase64(storage_path('app/voice/reference.wav')),
Authentica::fileToBase64(storage_path('app/voice/capture.wav'))
);
if ($result->successful()) {
// Voice match successful
} else {
// Handle failed verification
$error = $result->message();
}- User uploads or captures a reference image/audio during registration.
- Store the reference file securely (e.g., in
storage/app/faces/orstorage/app/voice/).
- Store the reference file securely (e.g., in
- User attempts to log in and provides a real-time image or audio.
- Convert both files to Base64:
$referenceBase64 = Authentica::fileToBase64($referencePath); // e.g., reference.jpg or reference.wav $queryBase64 = Authentica::fileToBase64($queryPath); // e.g., capture.jpg or capture.wav
- Call the verification method:
- Face:
$result = Authentica::verifyFace($userId, $referenceBase64, $queryBase64);
- Voice:
$result = Authentica::verifyVoice($userId, $referenceBase64, $queryBase64);
- Face:
- Check the result:
if ($result->successful()) { // Allow login or next step } else { // Show error message to user $error = $result->message(); }
- Both methods validate input and handle errors (invalid Base64, missing user ID, file too large, etc.).
- The response object provides helpers:
successful(),data(),message(), etc. - Always handle possible errors and inform the user accordingly.
Authentica::sendSms(
'+966551234567',
'Your order #12345 has shipped!',
'MyBrand' // Registered sender name
);$balance = Authentica::getBalance()->credits;- You can inject
AuthenticaClientdirectly if you prefer dependency injection. - All methods return an
AuthenticaResponseobject with helpers likesuccessful(),data(),message(), etc.
- Ensure you have published the config and set all required
.envvariables. - For more details, see the Authentica API documentation.
For technical inquiries: yacoub@yacoubalhaidari.com
