1. Go to this page and download the library: Download makise-co/auth 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/ */
makise-co / auth example snippets
// config/auth.php
return [
'guards' => [
// guard name
'token' => [
'class' => \MakiseCo\Auth\Guard\BearerTokenGuard::class,
'provider' => 'database',
'storageKey' => 'token',
]
],
'providers' => [
// user provider name
'database' => [
// your own user provider (should implement UserProviderInterface)
'class' => \App\Auth\MyUserProvider::class,
],
]
];
// your routes file
use MakiseCo\Auth\Guard\GuardInterface;
use MakiseCo\Auth\Http\Middleware\AuthorizationMiddleware;
use MakiseCo\Http\Router\RouteCollectorInterface;
/** @var RouteCollectorInterface $routes */
$routes->addGroup(
'/admin',
[
'namespace' => 'App\\Http\\Controller\\Admin\\',
'middleware' => [
\MakiseCo\Auth\Http\Middleware\AuthenticationMiddleware::class,
],
'attributes' => [
// auth guard name
GuardInterface::class => 'token',
],
],
function (RouteCollectorInterface $routes) {
$routes
->get('/users', 'UserController@index')
// check user's access rights
->withMiddleware(AuthorizationMiddleware::class)
// user must have an "admin" role
->withAttribute(AuthorizationMiddleware::ROLES, ['admin']);
}
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.