LaravelPackages.net
Acme Inc.
Toggle sidebar
sawolabs/sawo-laravel

Passwordless and OTP-less Authentication for your website. It helps you to authenticate user via their email or phone number.

15
0
1.1.0
About sawolabs/sawo-laravel

sawolabs/sawo-laravel is a Laravel package for passwordless and otp-less authentication for your website. it helps you to authenticate user via their email or phone number.. It currently has 0 GitHub stars and 15 downloads on Packagist (latest version 1.1.0). Install it with composer require sawolabs/sawo-laravel. Discover more Laravel packages by sawolabs or browse all Laravel packages to compare alternatives.

Last updated

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.

<?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.

Comments