PHPackages                             mjacques3/lumen-passport - 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. mjacques3/lumen-passport

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

mjacques3/lumen-passport
========================

Making Laravel Passport work with Lumen

0.3.4(5y ago)06MITPHPPHP &gt;=5.6.4

Since Aug 23Pushed 5y agoCompare

[ Source](https://github.com/mjacques-notur/lumen-passport)[ Packagist](https://packagist.org/packages/mjacques3/lumen-passport)[ Docs](https://github.com/dusterio/lumen-passport)[ RSS](/packages/mjacques3-lumen-passport/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (36)Used By (0)

lumen-passport
==============

[](#lumen-passport)

[![Build Status](https://camo.githubusercontent.com/58eb9c605f8f90e343bc25fec20ba099d15ab88ff494d75358f4819e487d0e74/68747470733a2f2f7472617669732d63692e6f72672f647573746572696f2f6c756d656e2d70617373706f72742e737667)](https://travis-ci.org/dusterio/lumen-passport)[![Code Climate](https://camo.githubusercontent.com/e06a948c642bab020853d092c3e6910e8489345b99c17ed2b6657ef2d1720a31/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f647573746572696f2f6c756d656e2d70617373706f72742f6261646765732f6770612e737667)](https://codeclimate.com/github/dusterio/lumen-passport/badges)[![Total Downloads](https://camo.githubusercontent.com/63bd7b349693cbbcf91afd28f2e16f59fd50bb4a21e4ec8af529dcd6ccf2f0d6/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c756d656e2d70617373706f72742f642f746f74616c2e737667)](https://packagist.org/packages/dusterio/lumen-passport)[![Latest Stable Version](https://camo.githubusercontent.com/453ad05908a9fdda619e438269e8caaeb4367b2cf4af3f6bf41fa949dae03703/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c756d656e2d70617373706f72742f762f737461626c652e737667)](https://packagist.org/packages/dusterio/lumen-passport)[![Latest Unstable Version](https://camo.githubusercontent.com/927af090fe1aed0cb0219230750516cb5906eaacae82b257e68f29edcebf32e4/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c756d656e2d70617373706f72742f762f756e737461626c652e737667)](https://packagist.org/packages/dusterio/lumen-passport)[![License](https://camo.githubusercontent.com/df44d50c39daa06d75990644a0725e3b3014235909849c9506d6e9c71b095bf8/68747470733a2f2f706f7365722e707567782e6f72672f647573746572696f2f6c756d656e2d70617373706f72742f6c6963656e73652e737667)](https://packagist.org/packages/dusterio/lumen-passport)

Making Laravel Passport work with Lumen

A simple service provider that makes Laravel Passport work with Lumen

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.6.3
- Lumen &gt;= 5.3

Installation via Composer
-------------------------

[](#installation-via-composer)

First install Lumen if you don't have it yet:

```
$ composer create-project --prefer-dist laravel/lumen lumen-app
```

Then install Lumen Passport (it will fetch Laravel Passport along):

```
$ cd lumen-app
$ composer require dusterio/lumen-passport
```

Or if you prefer, edit `composer.json` manually:

```
{
    "require": {
        "dusterio/lumen-passport": "^0.3.0"
    }
}
```

### Modify the bootstrap flow (`bootstrap/app.php` file)

[](#modify-the-bootstrap-flow-bootstrapappphp-file)

We need to enable both Laravel Passport provider and Lumen-specific provider:

```
// Enable Facades
$app->withFacades();

// Enable Eloquent
$app->withEloquent();

// Enable auth middleware (shipped with Lumen)
$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

// Finally register two service providers - original one and Lumen adapter
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
```

### Using with Laravel Passport 7.3.2 and newer

[](#using-with-laravel-passport-732-and-newer)

Laravel Passport 7.3.2 had a breaking change - new method introduced on Application class that exists in Laravel but not in Lumen. You could either lock in to an older version or swap the Application class like follows at the top of your `bootstrap/app.php` file:

```
$app = new \Dusterio\LumenPassport\Lumen7Application(
    dirname(__DIR__)
);
```

If you look inside this class - all it does is adding an extra method configurationIsCached() that always returns false.

### Migrate and install Laravel Passport

[](#migrate-and-install-laravel-passport)

```
# Create new tables for Passport
php artisan migrate

# Install encryption keys and other necessary stuff for Passport
php artisan passport:install
```

### Installed routes

[](#installed-routes)

This package mounts the following routes after you call routes() method (see instructions below):

VerbPathNamedRouteControllerActionMiddlewarePOST/oauth/token\\Laravel\\Passport\\Http\\Controllers\\AccessTokenControllerissueToken-GET/oauth/tokens\\Laravel\\Passport\\Http\\Controllers\\AuthorizedAccessTokenControllerforUserauthDELETE/oauth/tokens/{token\_id}\\Laravel\\Passport\\Http\\Controllers\\AuthorizedAccessTokenControllerdestroyauthPOST/oauth/token/refresh\\Laravel\\Passport\\Http\\Controllers\\TransientTokenControllerrefreshauthGET/oauth/clients\\Laravel\\Passport\\Http\\Controllers\\ClientControllerforUserauthPOST/oauth/clients\\Laravel\\Passport\\Http\\Controllers\\ClientControllerstoreauthPUT/oauth/clients/{client\_id}\\Laravel\\Passport\\Http\\Controllers\\ClientControllerupdateauthDELETE/oauth/clients/{client\_id}\\Laravel\\Passport\\Http\\Controllers\\ClientControllerdestroyauthGET/oauth/scopes\\Laravel\\Passport\\Http\\Controllers\\ScopeControllerallauthGET/oauth/personal-access-tokens\\Laravel\\Passport\\Http\\Controllers\\PersonalAccessTokenControllerforUserauthPOST/oauth/personal-access-tokens\\Laravel\\Passport\\Http\\Controllers\\PersonalAccessTokenControllerstoreauthDELETE/oauth/personal-access-tokens/{token\_id}\\Laravel\\Passport\\Http\\Controllers\\PersonalAccessTokenControllerdestroyauthPlease note that some of the Laravel Passport's routes had to 'go away' because they are web-related and rely on sessions (eg. authorise pages). Lumen is an API framework so only API-related routes are present.

Configuration
-------------

[](#configuration)

Edit config/auth.php to suit your needs. A simple example:

```
return [
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

    'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\User::class
        ]
    ]
];
```

Load the config in `bootstrap/app.php` since Lumen doesn't load config files automatically:

```
$app->configure('auth');
```

Registering Routes
------------------

[](#registering-routes)

Next, you should call the LumenPassport::routes method within the boot method of your application (one of your service providers). This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens:

```
\Dusterio\LumenPassport\LumenPassport::routes($this->app);
```

You can add that into an existing group, or add use this route registrar independently like so;

```
\Dusterio\LumenPassport\LumenPassport::routes($this->app, ['prefix' => 'v1/oauth']);
```

User model
----------

[](#user-model)

Make sure your user model uses Passport's `HasApiTokens` trait, eg.:

```
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
    use HasApiTokens, Authenticatable, Authorizable;

    /* rest of the model */
}
```

Extra features
--------------

[](#extra-features)

There are a couple of extra features that aren't present in Laravel Passport

### Allowing multiple tokens per client

[](#allowing-multiple-tokens-per-client)

Sometimes it's handy to allow multiple access tokens per password grant client. Eg. user logs in from several browsers simultaneously. Currently Laravel Passport does not allow that.

```
use Dusterio\LumenPassport\LumenPassport;

// Somewhere in your application service provider or bootstrap process
LumenPassport::allowMultipleTokens();
```

### Different TTLs for different password clients

[](#different-ttls-for-different-password-clients)

Laravel Passport allows to set one global TTL for access tokens, but it may be useful sometimes to set different TTLs for different clients (eg. mobile users get more time than desktop users).

Simply do the following in your service provider:

```
// Second parameter is the client Id
LumenPassport::tokensExpireIn(Carbon::now()->addYears(50), 2);
```

If you don't specify client Id, it will simply fall back to Laravel Passport implementation.

### Console command for purging expired tokens

[](#console-command-for-purging-expired-tokens)

Simply run `php artisan passport:purge` to remove expired refresh tokens and their corresponding access tokens from the database.

Running with Apache httpd
-------------------------

[](#running-with-apache-httpd)

If you are using Apache web server, it may strip Authorization headers and thus break Passport.

Add the following either to your config directly or to `.htaccess`:

```
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

```

Video tutorials
---------------

[](#video-tutorials)

I've just started a educational YouTube channel that will cover top IT trends in software development and DevOps: [config.sys](https://www.youtube.com/channel/UCIvUJ1iVRjJP_xL0CD7cMpg)

Also I'm happy to announce my newest tool – [GrammarCI](https://www.grammarci.com/), an automated (as a part of CI/CD process) spelling and grammar checks for your code so that your users don't see your typos :)

License
-------

[](#license)

The MIT License (MIT) Copyright (c) 2016 Denis Mysenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 74% 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 ~48 days

Recently: every ~41 days

Total

35

Last Release

1908d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.5.0

0.1.1PHP &gt;=5.6.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b466bddf4b2efef292f6d5324bbec44d35e6be2e3d182b8422184109b417cac4?d=identicon)[MJacques3](/maintainers/MJacques3)

---

Top Contributors

[![dusterio](https://avatars.githubusercontent.com/u/11039918?v=4)](https://github.com/dusterio "dusterio (57 commits)")[![mjacques-notur](https://avatars.githubusercontent.com/u/64915994?v=4)](https://github.com/mjacques-notur "mjacques-notur (3 commits)")[![andrew-s](https://avatars.githubusercontent.com/u/479306?v=4)](https://github.com/andrew-s "andrew-s (3 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (2 commits)")[![chris-doehring](https://avatars.githubusercontent.com/u/6341536?v=4)](https://github.com/chris-doehring "chris-doehring (2 commits)")[![jmarcher](https://avatars.githubusercontent.com/u/686843?v=4)](https://github.com/jmarcher "jmarcher (2 commits)")[![reed-jones](https://avatars.githubusercontent.com/u/11511864?v=4)](https://github.com/reed-jones "reed-jones (2 commits)")[![santilorenzo](https://avatars.githubusercontent.com/u/3186441?v=4)](https://github.com/santilorenzo "santilorenzo (2 commits)")[![ssgtcookie](https://avatars.githubusercontent.com/u/7977693?v=4)](https://github.com/ssgtcookie "ssgtcookie (1 commits)")[![theissn](https://avatars.githubusercontent.com/u/5305773?v=4)](https://github.com/theissn "theissn (1 commits)")[![JuanDMeGon](https://avatars.githubusercontent.com/u/5510960?v=4)](https://github.com/JuanDMeGon "JuanDMeGon (1 commits)")[![benwilkins](https://avatars.githubusercontent.com/u/1360229?v=4)](https://github.com/benwilkins "benwilkins (1 commits)")

---

Tags

phplumenlaravel passport

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mjacques3-lumen-passport/health.svg)

```
[![Health](https://phpackages.com/badges/mjacques3-lumen-passport/health.svg)](https://phpackages.com/packages/mjacques3-lumen-passport)
```

###  Alternatives

[dusterio/lumen-passport

Making Laravel Passport work with Lumen

6511.3M9](/packages/dusterio-lumen-passport)

PHPackages © 2026

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