PHPackages                             kayrules/lumen-passport-mongodb - 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. [Database &amp; ORM](/categories/database)
4. /
5. kayrules/lumen-passport-mongodb

ActiveLibrary[Database &amp; ORM](/categories/database)

kayrules/lumen-passport-mongodb
===============================

Making Laravel Passport work with Lumen and MongoDB

0.4.0(7y ago)65747[1 issues](https://github.com/kayrules/lumen-passport-mongodb/issues)MITPHPPHP &gt;=5.6.4

Since Aug 23Pushed 7y ago4 watchersCompare

[ Source](https://github.com/kayrules/lumen-passport-mongodb)[ Packagist](https://packagist.org/packages/kayrules/lumen-passport-mongodb)[ Docs](https://github.com/kayrules/lumen-passport-mongodb)[ RSS](/packages/kayrules-lumen-passport-mongodb/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (6)Versions (17)Used By (0)

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

[](#lumen-passport-mongodb)

[![Latest Stable Version](https://camo.githubusercontent.com/d2560986fac0257141875c05ab6038addf4e81bbfe329bf6ec7b02fc0e909fe5/68747470733a2f2f706f7365722e707567782e6f72672f6b617972756c65732f6c756d656e2d70617373706f72742d6d6f6e676f64622f762f737461626c652e737667)](https://packagist.org/packages/kayrules/lumen-passport-mongodb)[![Latest Unstable Version](https://camo.githubusercontent.com/beefca32a1bf77982112b43dd91e6603ce1dea315fa90d234185972c5054e2bb/68747470733a2f2f706f7365722e707567782e6f72672f6b617972756c65732f6c756d656e2d70617373706f72742d6d6f6e676f64622f762f756e737461626c652e737667)](https://packagist.org/packages/kayrules/lumen-passport-mongodb)[![License](https://camo.githubusercontent.com/7c48ec23ca1629ef4d0732bda01d16b74c03ede45860e053f6ccd75f8679221d/68747470733a2f2f706f7365722e707567782e6f72672f6b617972756c65732f6c756d656e2d70617373706f72742d6d6f6e676f64622f6c6963656e73652e737667)](https://packagist.org/packages/kayrules/lumen-passport-mongodb)

Making Laravel Passport work with Lumen and MongoDB

This repository was forked from [dusterio/lumen-passport](https://github.com/dusterio/lumen-passport) and added [lucas-cardial/laravel-passport-mongodb](https://github.com/lucca-cardial/laravel-passport-mongodb) package to make Laravel Passport work with Lumen and MongoDB.

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

[](#dependencies)

- PHP &gt;= 5.6.3
- Lumen &gt;= 5.3
- jenssegers/mongodb &gt;=3.2
- lucas-cardial/laravel-passport-mongodb &gt;= 1.0

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 kayrules/lumen-passport-mongodb
```

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

```
{
    "require": {
        "kayrules/lumen-passport-mongodb": "^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();

// Register jenssegers/mongodb service provider before `$app->withEloquent()`
$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);

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

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

// Finally register service providers
$app->register(Kayrules\LumenPassport\PassportServiceProvider::class);
```

### 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)

Adding this service provider, will mount the following routes.

VerbPathNamedRouteControllerActionMiddlewarePOST/oauth/tokenAccessTokenControllerissueToken-GET/oauth/tokensAuthorizedAccessTokenControllerforUserauthDELETE/oauth/tokens/{token\_id}AuthorizedAccessTokenControllerdestroyauthPOST/oauth/token/refreshTransientTokenControllerrefreshauthGET/oauth/clientsClientControllerforUserauthPOST/oauth/clientsClientControllerstoreauthPUT/oauth/clients/{client\_id}ClientControllerupdateauthDELETE/oauth/clients/{client\_id}ClientControllerdestroyauthGET/oauth/scopesScopeControllerallauthGET/oauth/personal-access-tokensPersonalAccessTokenControllerforUserauthPOST/oauth/personal-access-tokensPersonalAccessTokenControllerstoreauthDELETE/oauth/personal-access-tokens/{token\_id}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/api.php to add prefix to all API endpoints. (Eg: `/api/oauth/token`)

```
return [
	'prefix' => env('API_PREFIX', 'api')
];
```

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
        ]
    ]
];
```

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

[](#user-model)

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

```
use MoeenBasra\LaravelPassportMongoDB\HasApiTokens;

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 Kayrules\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]

```

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

30

—

LowBetter than 64% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~58 days

Recently: every ~173 days

Total

16

Last Release

2678d 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/d13f8e79cd33f98a0e274a001bb797353cd14aac8cfa3f958d4c850d36218998?d=identicon)[kayrules](/maintainers/kayrules)

---

Top Contributors

[![dusterio](https://avatars.githubusercontent.com/u/11039918?v=4)](https://github.com/dusterio "dusterio (24 commits)")[![kayrules](https://avatars.githubusercontent.com/u/461079?v=4)](https://github.com/kayrules "kayrules (19 commits)")[![lucascardial](https://avatars.githubusercontent.com/u/15651193?v=4)](https://github.com/lucascardial "lucascardial (4 commits)")[![jmarcher](https://avatars.githubusercontent.com/u/686843?v=4)](https://github.com/jmarcher "jmarcher (2 commits)")[![ssgtcookie](https://avatars.githubusercontent.com/u/7977693?v=4)](https://github.com/ssgtcookie "ssgtcookie (1 commits)")

---

Tags

phplumenmongodblaravel passport

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[dusterio/lumen-passport

Making Laravel Passport work with Lumen

6511.3M9](/packages/dusterio-lumen-passport)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2031.2M2](/packages/glushkovds-phpclickhouse-laravel)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)

PHPackages © 2026

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