sawolabs / sawo-laravel
Passwordless and OTP-less Authentication for your website. It helps you to authenticate user via their email or phone number.
Requires
- php: ^7.3|^8.0
This package is not auto-updated.
Last update: 2023-09-20 20:29:54 UTC
README
Table of Contents
Overview
Sawo provides the api and infrastructure you need to authenticate your users in PHP.
For more information, visit the Sawo SDK documentation.
Installation
To get started with Sawo, use the Composer package manager to add the package to your project's dependencies:
$ composer require sawolabs/sawo-laravel
Configuration
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
Add Sawo login form to blade template
Include the following include part in your login blade template to show Sawo Auth dialog
@include('sawo::auth')
Verifying User Token
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']); } });
Click here to visit example project
License
Sawo SDK is licensed under the MIT License.