Sawo provides the api and infrastructure you need to authenticate your users in PHP.
For more information, visit the Sawo SDK documentation.
To get started with Sawo, use the Composer package manager to add the package to your project's dependencies:
$ composer require sawolabs/sawo-laravel
Before using Sawo, you will need to add credentials for the your application. These credentials should be placed in your application's config/sawo.php
configuration file.
<?php
return [
/*
|--------------------------------------------------------------------------
| Configure Sawo defaults
|--------------------------------------------------------------------------
|
| Supported Identifier Types: "phone_number_sms", "email"
|
*/
'api_key' => env('SAWO_API_KEY', ''),
'api_secret_key' => env('SAWO_SECRET_KEY', ''),
'identifier_type' => env('SAWO_IDENTIFIER_TYPE', 'email'),
'redirect_url' => env('SAWO_REDIRECT', ''),
];
then add the following in the .env file
SAWO_API_KEY=<YOUR_SAWO_API_KEY_HERE>
SAWO_SECRET_KEY=<YOUR_SAWO_SECRET_KEY_HERE>
SAWO_IDENTIFIER_TYPE=phone_number_sms
SAWO_REDIRECT=https://yourdomain.com/sawo/callback
Include the following include part in your login blade template to show Sawo Auth dialog
@include('sawo::auth')
use SawoLabs\Laravel\Sawo;
Route::get('/sawo/callback', function () {
$userData = $request->only('user_id', 'created_on', 'identifier', 'identifier_type', 'verification_token');
$isVerified = Sawo::validateToken($userData['user_id'], $userData['verification_token']);
// If user is identifying via phone
if ('phone_number_sms' == $userData['identifier_type']) {
$user = User::where('phone', $userData['identifier'])->first();
} elseif ('email' == $userData['identifier_type']) {
$user = User::where('email', $userData['identifier'])->first();
}
if (empty($user)) {
$user = new \App\Models\User();
$user->phone = $userData['identifier'];
$user->email = $userData['identifier'];
$user->password = bcrypt($userData['verification_token']);
}
});
Sawo SDK is licensed under the MIT License.