PHPackages                             n3xt0r/laravel-passport-modern-scopes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. n3xt0r/laravel-passport-modern-scopes

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

n3xt0r/laravel-passport-modern-scopes
=====================================

Modern scope management for Laravel Passport

2.2.0(1mo ago)02.3k↓27.8%1[1 PRs](https://github.com/N3XT0R/laravel-passport-modern-scopes/pulls)1MITPHPPHP ^8.3|^8.4|^8.5CI passing

Since Dec 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/N3XT0R/laravel-passport-modern-scopes)[ Packagist](https://packagist.org/packages/n3xt0r/laravel-passport-modern-scopes)[ Docs](https://github.com/N3XT0R/laravel-passport-modern-scopes)[ RSS](/packages/n3xt0r-laravel-passport-modern-scopes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (6)Used By (1)

[![Latest Version on Packagist](https://camo.githubusercontent.com/42b3ea2963cc58ee7bf85d0f70419f5c8dbbad2e4ada4b67c24894f4380b4639/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e33787430722f6c61726176656c2d70617373706f72742d6d6f6465726e2d73636f7065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/n3xt0r/laravel-passport-modern-scopes)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6e2ed604bb026765858e16d71b644ca5d24570935f06b3c483e542cd1577ff7d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e33787430722f6c61726176656c2d70617373706f72742d6d6f6465726e2d73636f7065732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/n3xt0r/laravel-passport-modern-scopes/actions?query=workflow%3Atests+branch%3Amain)[![Maintainability](https://camo.githubusercontent.com/4df96c52da941b5b1655743d6619babe29c0063bb35e1124dd7443e10ea44803/68747470733a2f2f716c74792e73682f67682f4e33585430522f70726f6a656374732f6c61726176656c2d70617373706f72742d6d6f6465726e2d73636f7065732f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/N3XT0R/projects/laravel-passport-modern-scopes)[![Code Coverage](https://camo.githubusercontent.com/793abaf50d94f46d0e68c35a27cf556e529a4a52c2a9896cdd7c7b5107f1d742/68747470733a2f2f716c74792e73682f67682f4e33585430522f70726f6a656374732f6c61726176656c2d70617373706f72742d6d6f6465726e2d73636f7065732f636f7665726167652e737667)](https://qlty.sh/gh/N3XT0R/projects/laravel-passport-modern-scopes)[![Total Downloads](https://camo.githubusercontent.com/7525dc10ccde871cd0298be219de82f6ca32c5debcf83bb9608cc2c5a04d2586/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e33787430722f6c61726176656c2d70617373706f72742d6d6f6465726e2d73636f7065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/n3xt0r/laravel-passport-modern-scopes)

---

Passport Modern Scopes
======================

[](#passport-modern-scopes)

---

Attribute-based OAuth Scope Enforcement
---------------------------------------

[](#attribute-based-oauth-scope-enforcement)

Laravel Passport traditionally enforces OAuth scopes at the routing level, typically via middleware definitions in route files. While functional, this approach tends to scatter authorization rules across routes and couples controllers to infrastructure-level concerns.

This package introduces an **attribute-based approach** to OAuth scope enforcement.

By leveraging PHP 8 attributes and a single resolving middleware, required OAuth scopes can be declared **directly on controllers or controller actions**, keeping authorization rules close to the code they protect while remaining fully compatible with Laravel Passport.

### Key ideas

[](#key-ideas)

- OAuth scopes are **declared, not wired**
- Controllers express **requirements**, not middleware mechanics
- Passport remains untouched and fully in control of token validation
- Routes stay clean and infrastructure-agnostic

### Example

[](#example)

```
use N3XT0R\PassportModernScopes\Support\Attributes\RequiresScope;
use N3XT0R\PassportModernScopes\Support\Attributes\RequiresAnyScope;

#[RequiresScope('users:read')]
final class UserController
{
    public function index()
    {
        // Requires users:read
    }

    #[RequiresAnyScope('users:update', 'users:write')]
    public function update()
    {
        // Requires at least one of the given scopes
    }
}
```

A single middleware inspects controller attributes at runtime and enforces them using Laravel Passport’s native scope checks (`tokenCan`). Authentication itself remains the responsibility of your configured guard (e.g. `auth:api`).

### Why attributes?

[](#why-attributes)

- Declarative and explicit
- No duplication between routes and controllers
- Easy to reason about during code review
- Static-analysis and documentation friendly
- No magic strings scattered across route definitions

This approach provides a clean separation between **authorization intent** and **HTTP wiring**, allowing Passport-based APIs to scale without losing clarity or consistency.

Installation
------------

[](#installation)

```
composer require n3xt0r/laravel-passport-modern-scopes:^2.0
```

The middleware is automatically registered via the package's service provider.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Total

4

Last Release

58d ago

Major Versions

1.0.0 → 2.0.02026-01-01

PHP version history (3 changes)1.0.0PHP ^8.4

2.0.0PHP ^8.3

2.1.0PHP ^8.3|^8.4|^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/8dbd2b0984ee6f62b6c5c3356b0e0cff2f2afa5c98c4d05272eb4356e080d545?d=identicon)[N3XT0R](/maintainers/N3XT0R)

---

Top Contributors

[![N3XT0R](https://avatars.githubusercontent.com/u/1297846?v=4)](https://github.com/N3XT0R "N3XT0R (91 commits)")

---

Tags

apiattributesauthorizationlaravellaravel-passportoauthoauth2php8scopeslaravelN3XT0Rlaravel passport

### Embed Badge

![Health badge](/badges/n3xt0r-laravel-passport-modern-scopes/health.svg)

```
[![Health](https://phpackages.com/badges/n3xt0r-laravel-passport-modern-scopes/health.svg)](https://phpackages.com/packages/n3xt0r-laravel-passport-modern-scopes)
```

###  Alternatives

[dusterio/lumen-passport

Making Laravel Passport work with Lumen

6511.3M9](/packages/dusterio-lumen-passport)[corbosman/laravel-passport-claims

Add claims to Laravel Passport JWT Tokens

88655.9k](/packages/corbosman-laravel-passport-claims)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

55342.3k2](/packages/jeremy379-laravel-openid-connect)[schedula/laravel-passport-socialite

The missing laravel passport feature for social authentication

4822.6k](/packages/schedula-laravel-passport-socialite)[denniseilander/laravel-passport-scopes-restriction

Restrict scopes for different Laravel Passport clients.

1630.6k](/packages/denniseilander-laravel-passport-scopes-restriction)[danjdewhurst/laravel-passport-facebook-login

Facebook Token Request Grant for Laravel Passport

2824.4k](/packages/danjdewhurst-laravel-passport-facebook-login)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
