laravel-passport-otp-grant maintained by moeen-basra
Description
Laravel Passport One Time Pin Grant
Author
Last update
2022/01/15 18:55
(dev-main)
License
Downloads
1 256
Tags
Laravel Passport OTP Grant
This is a small package for laravel passport otp authentication easy to integrate.
How to
Following are a few steps you need to follow to make it work.
- Install this package using the composer
composer require moeen-basra/laravel-passport-otp-grant
- Implement the
MoeenBasra\OneTimePinGrant\Interfaces\OneTimePinGrantUserInterfaceon your desired provider model.
use Illuminate\Foundation\Auth\User as BaseUser;
use MoeenBasra\OneTimePinGrant\Interfaces\OneTimePinGrantUserInterface;
class User extends BaseUser implements OneTimePinGrantUserInterface
{
//...
/**
* {@inheritDoc}
*/
public function findAndValidateForPassportOtpGrant(string $mobile_number, string $code)
{
if (!OneTimePin::validate($mobile_number, $code)) {
return null;
}
return static::firstOrCreate([
'mobile_number' => $mobile_number
]);
}
}
- This step is optional, add the service provider under the providers array in
config/app.php.
'providers' => [
//...
MoeenBasra\OneTimePinGrant\OneTimePinGrantServiceProvider::class,
]
That's it now you can call the otp login using same params you use for other passport end points
curl --location --request POST 'https://api.example.com/oauth/token' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--form 'username="mobile_number"' \
--form 'password="code"' \
--form 'grant_type="otp"' \
--form 'client_id="client_id"' \
--form 'client_secret="client_secret"' \
--form 'scope="*"'
More
You can check out the Laravel Passport official documentation for more details.
Contributions
You are welcome, you can create a pull request. You will be credited for any contribution.
Issues
If you are facing any problem feel free to report here.