mimmi20/mezzio-generic-authorization
Composer 安装命令:
composer require mimmi20/mezzio-generic-authorization
包简介
Provides a Generic Authorization middleware for Mezzio.
README 文档
README
Code Status
Installation
You can install the mezzio-generic-authorization library with Composer:
composer require mimmi20/mezzio-generic-authorization
Introduction
This component provides middleware for Mezzio and PSR-7 applications for authorizing specific routes based on ACL or RBAC systems.
Unlike in mezzio-authorization this library does not require
the ServerRequestInterface by default. This makes it possible to use this component in combination with mezzio-navigation.
If you are using the provided midleware, the route name is used as the resource.
An authorization system first needs authentication: to verify that an identity has access to something (i.e., is authorized) we first need the identity, which is provided during authentication.
Authentication is provided via the package
mezzio-authentication.
That library provides an AuthenticationMiddleware class that verify
credentials using the HTTP request, and stores the identity via a
PSR-7 request attribute.
The identity generated by mezzio-authentication is stored as the
request attribute Mezzio\Authentication\UserInterface as a
UserInterface implementation. That interface looks like the following:
namespace Mezzio\Authentication; interface UserInterface { /** * Get the unique user identity (id, username, email address or ...) */ public function getIdentity() : string; /** * Get all user roles * * @return Iterable */ public function getRoles() : iterable; /** * Get a detail $name if present, $default otherwise */ public function getDetail(string $name, $default = null); /** * Get all the details, if any */ public function getDetails() : array; }
mezzio-generic-authorization consumes this identity attribute. It checks if a
user's role (as retrieved from the UserInterface object) is authorized
(granted) to the perform the current HTTP request.
Authorization is performed using the isGranted() method of the AuthorizationInterface
public function isGranted(?string $role = null, ?string $resource = null, ?string $privilege = null, ?\Psr\Http\Message\ServerRequestInterface\ServerRequestInterface $request = null): bool;
Two adapters are available:
- mezzio-generic-authorization-rbac, which implements Role-Based Access Controls (RBAC)
- mezzio-generic-authorization-acl, which implements an Access Control List (ACL).
If you want to know more about authentication using middleware in PHP, we suggest reading the blog post "Authorize users using Middleware".
Authorization adapters
You can configure the authorization adapter to use via your service container
configuration. Specifically, you can either map the service name
Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface to a factory, or alias it
to the appropriate service.
For instance, using Mezzio container configuration, you could select the mezzio-authorization-acl adapter in either of the following ways:
-
Using an alias:
use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface; use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAcl; return [ 'dependencies' => [ // Using an alias: 'aliases' => [ AuthorizationInterface::class => LaminasAcl::class, ], ], ];
-
Mapping to a factory:
use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface; use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAclFactory; return [ 'dependencies' => [ // Using a factory: 'factories' => [ AuthorizationInterface::class => LaminasAclFactory::class, ], ], ];
We provide two different adapters.
- The RBAC adapter is provided by mezzio-generic-authorization-rbac.
- The ACL adapter is provided by mezzio-generic-authorization-acl.
Each adapter is installable via Composer:
composer require mimmi20/mezzio-generic-authorization-rbac
# or
composer require mimmi20/mezzio-generic-authorization-acl
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md.
mimmi20/mezzio-generic-authorization 适用场景与选型建议
mimmi20/mezzio-generic-authorization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 523.31k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「authorization」 「middleware」 「psr-7」 「psr-15」 「mezzio」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mimmi20/mezzio-generic-authorization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mimmi20/mezzio-generic-authorization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mimmi20/mezzio-generic-authorization 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Model of a web-based resource
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Interfaces for web resource models and services to retrieve and create them
Interface for a factory to create Psr\Http\Message\StreamInterface objects
统计信息
- 总下载量: 523.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 35
- 依赖项目数: 12
- 推荐数: 7
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-22