n3xt0r/laravel-passport-modern-scopes
Attribute-based OAuth scope enforcement for Laravel Passport. Declare required scopes directly on controllers/actions via PHP 8 attributes, then enforce them with a single middleware. Keeps routes clean and auth rules close to the code they protect.
user:read:own, user:read:all). This fits well in B2B, SaaS, or multi-tenant systems where role-based scopes (e.g., admin, user) are insufficient.Passport::scope) without requiring core Passport changes. Backward-compatible with existing scope-based auth.oauth_scopes or custom tables). No migrations provided; assumes manual setup or Passport’s default schema.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Scope Resolution Logic | High | Test edge cases (e.g., circular dependencies, malformed attributes). |
| Passport Version Lock | Medium | Pin to a specific Passport version in composer.json. |
| Policy Callback Complexity | Medium | Document resolver contracts and provide stub implementations. |
| Performance Overhead | Low | Benchmark scope resolution in high-throughput APIs. |
| Deprecation Risk | Low | Monitor for Passport v11+ compatibility. |
department, role)?App\Policies\ScopeResolver) be structured? Will they integrate with existing Gates/Policies?composer require laravel/passport).php artisan passport:install).composer require n3xt0r/laravel-passport-modern-scopes
php artisan vendor:publish --provider="N3xt0r\ModernScopes\ModernScopesServiceProvider"
config/auth.php or service provider.public function resolve($user, $scope)
{
return $user->role === 'admin' && $scope === 'user:read:all';
}
Passport::scope() with Passport::modernScope() in app/Http/Kernel.php.Passport::tokensCan() or custom assertions.department-based access).Passport::enableScopeLogging() to trace denied requests.telescope or laravel-debugbar to inspect scope resolution.Cache::remember) for high-throughput APIs.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Resolver Throws Exception | 500 errors | Wrap in try-catch, deny access. |
| Database Unavailable | Scope resolution fails | Fallback to cached resolvers. |
| Malformed Scope Request | Unauthorized access | Validate scope format in middleware. |
| Passport Token Revoked | Scope cache stale | Use Passport::refreshTokens(). |
How can I help you explore Laravel packages today?