1. Go to this page and download the library: Download enlivenapp/flight-shield library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
enlivenapp / flight-shield example snippets
// app/config/shield.php
return [
'routePrepend' => 'auth',
// ... your overrides here
];
use Enlivenapp\FlightShield\Middlewares\SessionAuthMiddleware;
Flight::route('/dashboard', function () {
$user = auth()->user();
echo 'Hello, ' . $user->username;
})->addMiddleware(new SessionAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\ChainAuthMiddleware;
Flight::route('/api/resource', function () {
// accessible by session, Bearer token, or HMAC
})->addMiddleware(new ChainAuthMiddleware(Flight::app()));
$user = auth()->user();
// Check group membership
$user->inGroup('admin'); // true if in 'admin'
$user->inGroup('admin', 'superadmin'); // true if in either
// Check permission
$user->can('users.edit');
// Modify via the Authorizable trait (no ORM handle needed)
$user->addGroup('editor');
$user->removeGroup('editor');
$user->addPermission('posts.create');
$user->addPermission('posts.create', true); // explicit deny
$user->removePermission('posts.create');
// Or use the management services directly
auth()->groups()->syncPermissions('editor', ['posts.create', 'posts.edit']);
auth()->permissions()->create('posts.create', 'Create blog posts');
use Enlivenapp\FlightShield\Middlewares\SessionAuthMiddleware;
Flight::route('/dashboard', function () { ... })
->addMiddleware(new SessionAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\TokenAuthMiddleware;
Flight::route('/api/data', function () { ... })
->addMiddleware(new TokenAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\HmacAuthMiddleware;
Flight::route('POST /api/webhook', function () { ... })
->addMiddleware(new HmacAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\JWTAuthMiddleware;
Flight::route('/api/secure', function () { ... })
->addMiddleware(new JWTAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\ChainAuthMiddleware;
Flight::route('/mixed', function () { ... })
->addMiddleware(new ChainAuthMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\GroupMiddleware;
Flight::group('/admin', function () { ... }, [
new GroupMiddleware(Flight::app(), 'admin', 'superadmin'),
]);
use Enlivenapp\FlightShield\Middlewares\PermissionMiddleware;
Flight::route('/posts/create', function () { ... })
->addMiddleware(new PermissionMiddleware(Flight::app(), 'posts.create'));
use Enlivenapp\FlightShield\Middlewares\ForcePasswordResetMiddleware;
Flight::route('/account', function () { ... })
->addMiddleware(new ForcePasswordResetMiddleware(Flight::app()));
use Enlivenapp\FlightShield\Middlewares\RateLimitMiddleware;
Flight::route('POST /custom-auth', function () { ... })
->addMiddleware(new RateLimitMiddleware(Flight::app()));
// app/config/shield.php - return the keys you want to override
return [
'routePrepend' => 'auth',
'default_authenticator' => 'session',
// ... any other overrides
];