Stars: 106
Forks: 33
Pull Requests: 8
Issues: 10
Watchers: 13
Last Updated: 2023-06-12 16:38:07
Authentication, authorization and access control for Slim and other micro-frameworks
License:
Languages: PHP
Authentication, authorization and access control for Slim Framework and other PHP micro-frameworks.
Features
Install using composer
composer require jasny/auth
Auth
is a composition class. It takes an authz, storage, and optionally a confirmation service.
use Jasny\Auth\Auth;
use Jasny\Auth\Authz\Levels;
$levels = new Levels(['user' => 1, 'moderator' => 10, 'admin' => 100]);
$auth = new Auth($levels, new AuthStorage());
session_start();
$auth->initialize();
// Later...
if (!$auth->is('admin')) {
http_response_code(403);
echo "Access denied";
exit();
}
The Auth
service isn't usable until it's initialized. This should be done after the session is started.
session_start();
$auth->initialize();