delboy1978uk/bone-passport
Composer 安装命令:
composer require delboy1978uk/bone-passport
包简介
ACL package for Bone Framework
README 文档
README
Passport package for Bone Framework
installation
Use Composer
composer require delboy1978uk/bone-passport
usage
Simply add to the config/packages.php
<?php // use statements here use Bone\Passport\PassportPackage; use Del\Passport\PassportPackage as DelPassportPackage; return [ 'packages' => [ // packages here..., DelPassportPackage::class, PassportPackage::class, ], // ... ];
Now run the bone command to pick up database changes, creating a database migration, then run them:
bone migrant:diff
bone migrant:migrate
roles
Roles can be set via the command line using the bone command
bone passport:role --help
Description:
Manages roles.
Usage:
passport:role <operation> <role>
Arguments:
operation add or remove
role The role name
You can assign a role to a user again by using the bone command
bone passport:admin --help
Description:
User role admin.
Usage:
passport:admin <operation> <role> <userId> [<entityId>]
Arguments:
operation grant or revoke
role The role name
userId The ID of the user
entityId The ID of the entity, if any
middleware
Bone Passport comes with an easy to use middleware to secure your routes. Anyone without the required credentionals will receive a 403 unauthorised response.
In your addRoutes() method in the package class, create the middleware first:
public function addRoutes(Container $c, Router $router): Router { $passportControl = $c->get(PassportControl::class); $middleware = new PassportControlMiddleware($passportControl); // routes here }
To secure an endpoint, you should already be using a middleware such as SessionAuth, which provides a PSR-7
RequestInterface with a User object set as the user attribute. Add to the array of middlware with the options you
require:
$router->map('GET', '/lock-me', [MyController::class, 'someAction'])->middlewares([ $c->get(SessionAuth::class), $middleware->withOptions('admin') ]);
entity ids
Sometimes a role will only be in control of various specific entities. For example, a league admin would be in charge of specific clubs in that league. Usually the ID of that entity will be in the URL. You can lock down this by passing the route variable name, like so:
$router->map('GET', '/books/edit/{id:number}', [MyController::class, 'someAction'])->middlewares([ $c->get(SessionAuth::class), $middleware->withOptions('book-admin', 'id') ]);
delboy1978uk/bone-passport 适用场景与选型建议
delboy1978uk/bone-passport 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 delboy1978uk/bone-passport 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 delboy1978uk/bone-passport 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 175
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-21