darshanadaptit/passport-otp-grant 问题修复 & 功能扩展

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

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

darshanadaptit/passport-otp-grant

Composer 安装命令:

composer require darshanadaptit/passport-otp-grant

包简介

passport otp grant for register and login whit verify code

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

this package help you to implement otp grant (register - login with verify code ore two verification code ) via laravel-passport

Installation

Via Composer

$ composer require darshanadaptit/passport-otp-grant

initial

1-install and initial Laravel passport in your project and create a password-client

2- add below two rows to your user migration ( if you want use custom rows see customizing section)

    //...
    $table->string('phone_number')->unique();
    $table->integer('otp')->nullable();
    //...

add use HasOTP; in your model :

<?php
class User extends Authenticatable
{
    use HasFactory, Notifiable, HasApiTokens, HasOTP;
    //...
    }

sample usage

below sample and logic is about login and register with otp. (it's not about two verification )

public function userLoginOrRegister(UserLoginRequest $request)
    {

        $user = $this->userModel->wherePhoneNumber($request['phone_number'])->first();
        if (!$user) {
            $user = $this->userModel->create(['phone_number' => $request['phone_number']]);
        }

        $user->otp = $code_verifier = rand(10000, 99999);
        //you can send otp code via sms , email , any messenger , ..... 
        $user->save();
        this->sendOtpCodeToUser(user);


    }
        
        
        

now you can verify user with passport like below

Request::create('/oauth/token',
            'POST',
            [
                'grant_type' => 'otp_grant',
                'client_id' => 'client_id',
                'client_secret' => client_secret',
                'phone_number' => 'phone_number',
                'otp' => 'otp',
                'scope' =>'',
            ]);

customising

<?php
class User extends Authenticatable
{
    use HasFactory, Notifiable, HasApiTokens, HasOTP;
    
    $phoneNumberColumn='anything';
    $OTPColumn='my_otp';
    //otp expire time in minute 
    $OTPExpireTime=15;
    //...
    }

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

to do list

  • change phone_number to user
  • add test
  • add CI

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固