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.
Full Changelog: https://github.com/N3XT0R/laravel-passport-modern-scopes/compare/2.2.0...2.2.1
Added support for Laravel 13
Full Changelog: https://github.com/N3XT0R/laravel-passport-modern-scopes/compare/2.1.0...2.2.0
This release introduces a new, attribute-driven way to define and enforce OAuth scopes when using Laravel Passport.
Instead of defining scope requirements in route files via middleware, required scopes can now be declared directly on controllers or controller actions using PHP 8 attributes. This keeps authorization rules close to the code they protect and significantly improves readability and maintainability.
You can now define required OAuth scopes using PHP attributes:
#[RequiresScope('users:read')]
class UserController
{
public function index()
{
// Requires users:read
}
#[RequiresAnyScope('users:update', 'users:write')]
public function update()
{
// Requires at least one of the given scopes
}
}
This approach removes the need to attach scope middleware in route definitions.
The resolving middleware can be:
This ensures compatibility with standard Laravel applications, Testbench, and Workbench environments.
Version 2.0.0 represents the first stable release of Passport Modern Scopes in its current architecture.
It provides a modern, expressive, and maintainable way to define OAuth scope requirements while staying fully aligned with Laravel and Passport best practices.
How can I help you explore Laravel packages today?