qiutuleng/laravel-passport-phone-verification-code-grant
Composer 安装命令:
composer require qiutuleng/laravel-passport-phone-verification-code-grant
包简介
Resource owner phone verification code credentials grant for Laravel Passport
README 文档
README
Introduction
Resource owner phone verification code credentials grant for Laravel Passport
Install
Under your working folder and run the command in terminal:
composer require qiutuleng/laravel-passport-phone-verification-code-grant
Setup
Laravel
If your laravel version is greater or equal to 5.5, the service provider will be attached automatically.
Other versions, you must needs add \QiuTuleng\PhoneVerificationCodeGrant\PhoneVerificationCodeGrantServiceProvider::class to the providers array in config/app.php:
'providers' => [ /* * Package Service Providers... */ ... \QiuTuleng\PhoneVerificationCodeGrant\PhoneVerificationCodeGrantServiceProvider::class, ]
Lumen
$app->register(\QiuTuleng\PhoneVerificationCodeGrant\PhoneVerificationCodeGrantServiceProvider::class);
How to use?
Configure
-
You must needs implement
\QiuTuleng\PhoneVerificationCodeGrant\Interfaces\PhoneVerificationCodeGrantUserInterfaceinterface in yourUsermodel.<?php namespace App; use Laravel\Passport\HasApiTokens; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use QiuTuleng\PhoneVerificationCodeGrant\Interfaces\PhoneVerificationCodeGrantUserInterface; class User extends Authenticatable implements PhoneVerificationCodeGrantUserInterface { use HasApiTokens, Notifiable; }
-
Add
findOrNewForPassportVerifyCodeGrantandvalidateForPassportVerifyCodeGrantmethods to yourUsermodel./** * Find or create a user by phone number * * @param $phoneNumber * @return \Illuminate\Database\Eloquent\Model|null */ public function findOrCreateForPassportVerifyCodeGrant($phoneNumber) { // If you need to automatically register the user. return static::firstOrCreate(['mobile' => $phoneNumber]); // If the phone number is not exists in users table, will be fail to authenticate. // return static::where('mobile', '=', $phoneNumber)->first(); } /** * Check the verification code is valid. * * @param $verificationCode * @return boolean */ public function validateForPassportVerifyCodeGrant($verificationCode) { // Check verification code is valid. // return \App\Code::where('mobile', $this->mobile)->where('code', '=', $verificationCode)->where('expired_at', '>', now()->toDatetimeString())->exists(); return true; }
-
(Optional) Also you can rename
phone_numberandverification_codefields in config file:To do this, add keys in
config/passport.php, example://... 'phone_verification' => [ 'phone_number_request_key' => 'phone', 'verification_code_request_key' => 'verification_code', ], //...
Request Tokens
You may request an access token by issuing a POST request to the /oauth/token route with the user's phone number and verification code.
$http = new GuzzleHttp\Client; $response = $http->post('http://your-app.com/oauth/token', [ 'form_params' => [ 'grant_type' => 'phone_verification_code', 'client_id' => 'client-id', 'client_secret' => 'client-secret', 'phone_number' => '+8613416292625', 'verification_code' => 927068, 'scope' => '', ], ]); return json_decode((string) $response->getBody(), true);
More
You can check out the Laravel/Passport official documentation to learn more
Contributing
You can create a pull requests to this repository.
Welcome your ideas or code.
Issues
If you have any questions, please ask your question in the Issues and I will try my best to help you.
qiutuleng/laravel-passport-phone-verification-code-grant 适用场景与选型建议
qiutuleng/laravel-passport-phone-verification-code-grant 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75.19k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2018 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 qiutuleng/laravel-passport-phone-verification-code-grant 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 qiutuleng/laravel-passport-phone-verification-code-grant 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 75.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-24