sawolabs/sawo-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sawolabs/sawo-laravel

Composer 安装命令:

composer require sawolabs/sawo-laravel

包简介

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

README 文档

README

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.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固