Skip to content

sawolabs/laravel-example

Repository files navigation

Sawo PHP SDK

Current version Supported PHP version

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.

'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', ''),

or same can be configured in .env

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']);
    }
    
});

Example Project link

License

Sawo SDK is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages