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

Security starter is a full implementation of laravel/passport and heloufir/simple-passport, containing all the implementations of the authentication and forgot password systems, which allows you to start your project from a good foundation, and only worry about the business logic of your application.

Notifications You must be signed in to change notification settings

heloufir/security-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Due to a time constraint, unfortunately this repository is no longer maintained.


Security-Starter is a ready to use package that provide to you a complete CRUD REST system for a User/Profile/Role architecture, and also provide a middleware to specify roles that the user must have to access your routes, and it's based on the **heloufir/simple-passport** package that offers to you a **forgot password** system, you can refer to this [link](https://github.com/heloufir/simple-passport) to know more about this package.

Security starter architecture

A full implementation

You can find a complete implementation of this repository in Ngx Security Starter

Installation

composer require heloufir/security-starter

Configuration

Method 1. You can configure this package automatically, by using the command php artisan starter:config (if you want to configure it manually, go to Method 2) When executing this command you will be asked to answer some questions, and at the very end you will need to complete 3 steps manually :

  • 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
];

Method 2. (Manual configuration)

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.

You can check the wiki for more information about this package.

About

Security starter is a full implementation of laravel/passport and heloufir/simple-passport, containing all the implementations of the authentication and forgot password systems, which allows you to start your project from a good foundation, and only worry about the business logic of your application.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages