Skip to content
/ auth Public

Basic Authentication and Authorization implementation

License

Notifications You must be signed in to change notification settings

makise-co/auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Makise-Co Auth

Authentication and Authorization implementation

Installation

  • Register service provider - MakiseCo\Auth\AuthServiceProvider
  • Minimal required configuration config

Example configuration

// 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,
        ],
    ]
];

Usage

// 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']);
    }
);

About

Basic Authentication and Authorization implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages