Convert client_id to Uuid in Laravel Passport

diadal

Diadal Nig Ltd

Posted on August 14, 2020

Convert client_id to Uuid in Laravel Passport




Convert client_id to Uuid in Laravel Passport

Build Status Total Downloads License

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

if you find this helpful you can buy me a coffee @ Patreon

💖 💪 🙅 🚩
diadal
Diadal Nig Ltd

Posted on August 14, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related