marcocastignoli/authorization 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marcocastignoli/authorization

Composer 安装命令:

composer require marcocastignoli/authorization

包简介

A package to manage authorization for Lumen

README 文档

README

Logo

authorization

Latest Stable Version Total Downloads Latest Unstable Version License

A package to manage authorization for Lumen

Dependencies

  • PHP >= 7.0
  • Lumen >= 5.3

Authentication system

First, you have to implement an authentication system, I suggest you to use "passport", for Lumen you can check this: https://github.com/dusterio/lumen-passport/

Installation via Composer

Install Lumen if you don't have it yet:

$ composer create-project --prefer-dist laravel/lumen lumen-app

Then install "authorization":

$ cd lumen-app
$ composer require marcocastignoli/authorization

Or if you prefer, edit composer.json manually:

{
    "require": {
        "marcocastignoli/authorization": "dev-master"
    }
}

Modify the bootstrap flow (bootstrap/app.php file)

// Enable Facades
$app->withFacades();

// Enable Eloquent
$app->withEloquent();

// Register the service provider
$app->register(marcocastignoli\authorization\AuthorizationProvider::class);

Migrate and seed the database

# Create new tables
php artisan migrate

# Seed the database
php artisan db:seed --class=marcocastignoli\\authorization\\AuthorizationSeeder

Documentation

This package provides a simple way to create permissions for your application.

Writing permissions

In the users table you have to assign to the user an auth level.

In the authorizations table you can create the permissions.

  • auth: a permission is referred to the user's auth level.
  • object: a permission is referred to a Lumen's model.
  • field: a permission is referred to a field of the object.
  • method: a permission is referred to the action of the request (get, put, post, del).
  • entity: a permission is referred to the entity of the request. (For example in "show all users" the entity is "all".)

Examples

For each sentence you can see its implementation in the authorizations table.

The user with authorization 0 can see the id of everyone

auth object field method entity
0 User id show all

The user with authorization 1 can see the email and the username of everyone

auth object field method entity
1 User email show all
1 User username show all

The user with authorization 2 can edit every field for his cars

auth object field method entity
2 Car * post my

Using permissions

Create a new Model

When you create a new model instead of extending Model, you have to extend AuthorizationScopes.

Inside every model you can use the following scopes to filter your queries.

  • show( $entity )
  • post( $entity, $arguments )
  • put( $entity, $arguments )
  • del( $entity, $id )

Examples

// Get information about my user using the permission set in the authorizations table
App\User::show("my")->get();

// Edit all cars where id < 5
App\Cars::where("id", "<", 5)->post("*", [
    "color"=>"red"
]);

All the scopes also work with relations, in every Model you have to create a public parameter called own. That is the field linked with the user's id.

License

The MIT License (MIT) Copyright (c) 2016 Marco Castignoli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固