Convert client_id to Uuid in Laravel Passport
Introduction
Laravel Passport is an OAuth2 server and API authentication package that is simple and enjoyable to use. This Package will enable you you convert client id and client_id to Uuid which is more secure and safe for production
Installation
composer require diadal/passport
Laravel 5.5 hight auto discover package you may need to register in your config app.php under providers
Diadal\Passport\PassportServiceProvider::class,
Next in app/Providers/AppServiceProvider.php
add \Laravel\Passport\Passport::ignoreMigrations();
to register
public function register()
{
//....
\Laravel\Passport\Passport::ignoreMigrations();
}
Next
php artisan config:clear
To publish Cilent Uuid migration use this
php artisan vendor:publish --tag=passport-cilent-migrations
if no file published try
php artisan config:clear
and retry php artisan vendor:publish --tag=passport-cilent-migrations
Note you can use this both
Migrate your Database
php artisan migrate
Next In AuthServiceProvider @ app/Providers/AuthServiceProvider.php
add use Diadal\Passport\Passport;
<?php
namespace App\Providers;
use Diadal\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
\Laravel\Passport\Passport::useClientModel(\Diadal\Passport\Client::class);
\Laravel\Passport\Passport::usePersonalAccessClientModel(\Diadal\Passport\PersonalAccessClient::class);
Passport::tokensCan([
'all' => 'All Function',
'create-invoice' => 'Create Invoice',
]);
Passport::tokensExpireIn(now()->addDays(15));
Passport::refreshTokensExpireIn(now()->addDays(30));
}
}
Next, you should run the passport:install
command
php artisan passport:install
php artisan config:clear
All default Laravel Passport remain the same
Official Documentation
Documentation for Passport can be found on the Laravel website.
Any issue check here
also you can buy me a coffee @ Patreon