Introduce First-Party Authorization Library with Adapter-Based RBAC Support
@charoyan88 đang làm issue này rồi.
Từ ngày 15/1/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Summary
Quantum Framework currently provides a robust first-party Auth library (session & JWT) that fully covers authentication concerns.
However, there is no first-party solution for authorization (permissions / access control).
This leads to:
- role checks scattered across controllers, services, and middlewares
- inconsistent authorization patterns across projects
- tight coupling between business logic and authentication details
This ticket proposes introducing a first-party Authorization library, designed in full alignment with QF architecture and philosophy:
- adapter-based (no runtime branching)
- explicit and class-driven
- backward compatible
- service-first
- middleware-safe
Goals
- Introduce a dedicated Authorization library (
Quantum\Libraries\Authorization) - Keep Auth and Authorization strictly separated
- Use permissions as the primary authorization primitive
- Support RBAC as the initial authorization model
- Allow multiple permission sources via adapters (config-based, DB-based)
- Preserve Laravel-like DX (
user()->can()) via delegation - Integrate cleanly with QF middlewares (no parameters)
- Provide a safe migration path from
users.role→ full RBAC tables
Non-Goals (v1)
- No ABAC / policies
- No route DSL or parameterized middleware
- No UI or admin tooling
- No breaking changes to Auth
- No removal of
users.role
Core Principles (QF-Aligned)
- Auth answers “who are you?”
- Authorization answers “what can you do?”
- Services enforce authorization
- Middlewares are coarse-grained gates
- Adapters decide behavior — methods never branch
- Explicit classes over magic strings
Proposed Structure
Quantum/Libraries/Authorization/
├── AuthorizationService.php
├── AuthorizationFactory.php
├── Authorization.php
├── Contracts/
│ └── PermissionResolverInterface.php
├── Adapters/
│ ├── ConfigPermissionAdapter.php
│ └── DatabasePermissionAdapter.php
└── Exceptions/
└── AuthorizationException.php
Core API
AuthorizationService
$authorization->can(User $user, string $permission, mixed $context = null): bool;
$authorization->authorize(User $user, string $permission, mixed $context = null): void;
User Convenience (DX Only)
$user->can('post.publish');
$user->authorize('post.publish');
Important:
- User does not implement authorization logic
- User only delegates to AuthorizationService
Adapter-Based Authorization (No Runtime Branching)
interface PermissionResolverInterface
{
public function can(User $user, string $permission, mixed $context = null): bool;
}
Middleware Integration (IMPORTANT)
Constraint
QtMiddleware::apply() does NOT accept parameters.
Correct Pattern
Each authorization middleware represents a named permission gate.
abstract class PermissionMiddleware extends QtMiddleware
{
public function apply(Request $request, Response $response, Closure $next)
{
$user = auth()->user();
if (!$user || !$user->can('post.publish')) {
return $response->setStatus(403);
}
return $next($request, $response);
}
}
Migration Path Summary
- Config RBAC +
users.role - Introduce RBAC tables
- Sync config → DB
- Switch adapter
- Backfill
user_roles - Deprecate
users.role
Acceptance Criteria
- Authorization is a first-party library
- Adapter-based resolution via factory
- No runtime branching based on config
- Middleware respects QtMiddleware constraints
- Service-level authorization enforced
- Backward compatibility preserved
- Ngôn ngữ chính
- PHP
- Star
- 36
- Fork
- 22
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của quantum-php/framework
-
routing testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
quantum-php/framework#547 ·
-
view
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
quantum-php/framework#542 ·
-
enhancement http
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
quantum-php/framework#565 · 1 bình luận ·
-
components view
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
quantum-php/framework#551 ·
-
Add explicit @version special route token support for API major versioning within a single module Đang mởrouting
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
quantum-php/framework#550 ·
Tất cả issue của quantum-php/framework
Issue tương tự
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Перевод устарел
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100