Introduce First-Party Authorization Library with Adapter-Based RBAC Support
@charoyan88 is already working on this.
Since Jan 15, 2026.
Assessment
This issue has not been assessed yet.
Description
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
- Dominant language
- PHP
- Stars
- 36
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantum-php/framework
-
routing testing
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quantum-php/framework#547 ·
-
view
Difficulty 1/5 Under an hour Newbie friendliness 75/100
quantum-php/framework#542 ·
-
enhancement http
Difficulty 5/5 Over a week Newbie friendliness 35/100
quantum-php/framework#565 · 1 comment ·
-
components view
Difficulty 5/5 Over a week Newbie friendliness 42/100
quantum-php/framework#551 ·
-
Add explicit @version special route token support for API major versioning within a single module Openrouting
Difficulty 5/5 Over a week Newbie friendliness 45/100
quantum-php/framework#550 ·
All issues in quantum-php/framework
Similar issues
-
status/awaiting_triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
WordPress/plugin-check#1486 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
az-digital/az_quickstart#6019 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
grokability/snipe-it#19688 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100