adolfocuadros/renqo-client-acl

包含连接到 RENQO ACL 服务器的必需工具

v0.6.1.2 2016-10-07 05:53 UTC

This package is auto-updated.

Last update: 2024-09-21 20:00:31 UTC


README

Renqo 客户端 ACL 是一个连接到 RENQO ACL 服务器 的工具,它将允许您轻松地管理系统中的权限和角色。

安装步骤

通过 Composer 安装

composer require adolfocuadros/renqo-client-acl

Laravel config/app.php

添加服务提供者

'providers' = [
    //Otros Proveedores de servicio
    //
    Adolfocuadros\RenqoClientACL\AclServiceProvider::class,
],

发布配置

Laravel artisan

php artisan vendor:publish --tag=config

Lumen:如果不存在配置文件夹,请创建它

vendor/adolfocuadros/client-auth/config/renqo_client_acl.php -> config/renqo_client_acl.php

##要修改的文件

config/renqo_client_acl.php

修改

//Server of Renqo ACL server
    'renqo_acl'     => 'http://url-to-renqo.com',
    'server_token'  => ''

注册中间件

Lumen:在 bootstrap/app.php 中

...
$app->routeMiddleware([
    //Otros Middleware
    
    'acl' => Adolfocuadros\RenqoClientACL\Middleware\CheckAclMiddleware::class,
]);


//Antes de cargar las rutas
$app->configure('renqo_client_acl');
...

###认证配置(仅限 Laravel)如果需要使用 RENQO ACL 认证和 ACL 服务器

打开 config/auth.php 文件并修改以下行

'guards' => [
        'web' => [
            'driver' => 'session',
            //'provider' => 'users',
            'provider' => 'renqo-acl'
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],
    
    //
    // Otras Configuraciones
    //
    
//Agregar un nuevo proveedor
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        //RENQOACL
        'renqo-acl' => [
            'driver' => 'renqo',
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

然后注册服务提供者 renqo-acl,打开文件 app/Providers/AuthServiceProvider

    public function boot()
    {
        $this->registerPolicies();

        \Auth::provider('renqo', function ($app, array $config) {
            return new \Adolfocuadros\RenqoClientACL\AuthUserProvider($config);
        });
    }

如何使用?

app/Http/routes.php

$app->post('usuarios', [
    'middleware' => 'acl:usuarios.store',
    'uses' => 'UsuarioController@store'
]);

注意 acl:usuarios.store 将与 session 一起验证 "usuarios.store" 权限,如果一切正常,则返回 HTTP 200,如果有问题,则返回 40x。

错误响应 HTTP 401

{"error":"No tiene los permisos suficientes."}

成功响应 HTTP 200

{"status":true}