Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

3.2. Manual configuration

EL OUFIR Hatim edited this page Mar 1, 2019 · 2 revisions

First, you need to publish the heloufir/simple-passport:

php artisan vendor:publish --provider=Heloufir\SimplePassport\SimplePassportServiceProvider

After, you need to publish the heloufir/security-starter:

php artisan vendor:publish --provider=Heloufir\SecurityStarter\SecurityStarterServiceProvider

Then, if you want to customize the profiles, roles, profile_roles and user_profiles tables you need first to update the file config/security-starter.php, then go to next step.

Launch migrations to add laravel/passport tables and heloufir/security-starter tables:

php artisan migrate

Then, install laravel/passport oauth clients, by executing:

php artisan passport:install

Add Laravel\Passport\HasApiTokens trait to the User model

<?php

namespace App;
    
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
    
class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

Add Heloufir\SecurityStarter\Core\UserProfiles trait to the User model

<?php

namespace App;
    
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Heloufir\SecurityStarter\Core\UserProfiles;
    
class User extends Authenticatable
{
    use HasApiTokens, Notifiable, UserProfiles;
}

Add 'roles' => \Heloufir\SecurityStarter\Http\Middleware\RoleMiddleware::class to the $routeMiddleware in Kernel

File: app/Http/Kernel.php

protected $routeMiddleware = [
    // ...
    'roles' => \Heloufir\SecurityStarter\Http\Middleware\RoleMiddleware::class
];

Don't forget to update the guards in your auth.php configuration file for the api to passport

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport', // <- Here
            'provider' => 'users',
        ],
    ],

That's all, the installation and configuration of security-starter is done.

Clone this wiki locally