mimmi20/mezzio-generic-authorization 问题修复 & 功能扩展

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

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

mimmi20/mezzio-generic-authorization

Composer 安装命令:

composer require mimmi20/mezzio-generic-authorization

包简介

Provides a Generic Authorization middleware for Mezzio.

README 文档

README

Latest Stable Version Latest Unstable Version License

Code Status

codecov Average time to resolve an issue Percentage of issues still open Mutation testing badge

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:

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.

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 mimmi20/mezzio-generic-authorization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 523.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 35
  • 依赖项目数: 12
  • 推荐数: 7

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-22