PHPackages                             yooslim/legit-artisan-commands - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. yooslim/legit-artisan-commands

ActiveLibrary[CLI &amp; Console](/categories/cli)

yooslim/legit-artisan-commands
==============================

A Laravel 9 package that allows you enforce security of your artisan commands by authenticating users before running.

v1.0.0-beta(3y ago)34MITPHPPHP ^8.0.2

Since Sep 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/yooslim/legit-artisan-commands)[ Packagist](https://packagist.org/packages/yooslim/legit-artisan-commands)[ RSS](/packages/yooslim-legit-artisan-commands/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Introduction
============

[](#introduction)

This package allows you as a developer to restrict who can and cannot run artisan commands, especially in a production environment. For example, a user (admin) should be allowed to run commands only if he has the right role/permission.

How it works ?
==============

[](#how-it-works-)

An artisan user will be provided with a token in order to use it as an option when running commands. This token has a configurable size and lifetime. The user can use this token as much as he wants until it expires or is revoked.

In order to get this token, an artisan user must first perform an authentication within the console, if the authentication is successful, the user will be prompted with the token, otherwise, a warning message will be displayed.

The logic of authentication is customizable, the developer can put in place his own validation rules. For exemple, one would want to authorize a user only if he has an "admin" role, an other one would check if he has the right permissions, another one would fetch an active directory or external authentication service, etc.

How to implement it !
=====================

[](#how-to-implement-it-)

A few steps to put this in place.

### Install the package

[](#install-the-package)

`composer require yooslim/legit-artisan-commands`

### Publish the vendor configuration file

[](#publish-the-vendor-configuration-file)

`php artisan vendor:publish --provider="YOoSlim\LegitArtisanCommands\Providers\LegitCommandsServiceProvider"`

### Edit configuration file

[](#edit-configuration-file)

- **Token lifetime**: The console token lifetime in seconds.
- **Token size**: The number of caracters to be generated (must be less than 255).
- **Environments to be ignored**: No need to waste our time with authentication in local environments, so it possible to ignore a set of environments.
- **User model relationship**: The model name (namespace included) of the user entity.

### Run migrations

[](#run-migrations)

`php artisan migrate`

### Add the ArtisanUserInterface to the user model

[](#add-the-artisanuserinterface-to-the-user-model)

```
