jasny/auth

Authentication, authorization and access control for Slim Framework and other PHP micro-frameworks

Maintainers

👁 jasny

Package info

github.com/jasny/auth

Homepage

pkg:composer/jasny/auth

Statistics

Installs: 16 943

Dependents: 1

Suggesters: 0

Stars: 113

Open Issues: 1

v2.2.1 2024-08-30 14:18 UTC

Suggests

None

Provides

None

Conflicts

Replaces

None

MIT c36acab0518437bca5b69721ec51a0d48316c931

authslimjwtpsr-7psr-15


README

👁 jasny-banner

Jasny Auth

👁 PHP
👁 Scrutinizer Code Quality
👁 Code Coverage
👁 Packagist Stable Version
👁 Packagist License

Authentication, authorization and access control for Slim Framework and other PHP micro-frameworks.

Features

Installation

Install using composer

composer require jasny/auth

Usage

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();

Documentation