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

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

thesalmankhimani/lumen-passport-mongodb
=======================================

Making Laravel Passport work with Lumen and MongoDB

0.1.0(6y ago)013MITPHPPHP &gt;=5.6.4

Since Aug 29Pushed 6y agoCompare

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

READMEChangelogDependencies (6)Versions (2)Used By (0)

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

[](#lumen-passport-mongodb)

[![Latest Stable Version](https://camo.githubusercontent.com/b2537129fc801a921b92483b643440b12a2eaf175c85f64f9fa81fdca343fd34/68747470733a2f2f706f7365722e707567782e6f72672f74686573616c6d616e6b68696d616e692f6c756d656e2d70617373706f72742d6d6f6e676f64622f762f737461626c652e737667)](https://packagist.org/packages/thesalmankhimani/lumen-passport-mongodb)[![Latest Unstable Version](https://camo.githubusercontent.com/c23da3fe7e5ff291c5e0b16aa110b8b815ba7a0542c307d5dc1a315567d79db8/68747470733a2f2f706f7365722e707567782e6f72672f74686573616c6d616e6b68696d616e692f6c756d656e2d70617373706f72742d6d6f6e676f64622f762f756e737461626c652e737667)](https://packagist.org/packages/thesalmankhimani/lumen-passport-mongodb)[![License](https://camo.githubusercontent.com/133b6c52b008ac2bec6634b63a7d10b9cb1e1e29486431af0897ce5a9f3fb0df/68747470733a2f2f706f7365722e707567782e6f72672f74686573616c6d616e6b68696d616e692f6c756d656e2d70617373706f72742d6d6f6e676f64622f6c6963656e73652e737667)](https://packagist.org/packages/thesalmankhimani/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 [thesalmankhimani/laravel-passport-mongodb](https://github.com/thesalmankhimani/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
- theslamankhimani/laravel-passport-mongodb &gt;= 0.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 thesalmankhimani/lumen-passport-mongodb
```

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

```
{
    "require": {
        "thesalmankhimani/lumen-passport-mongodb": "^0.1.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(\SalKhimani\LaravelPassportMongoDB\PassportServiceProvider::class);
$app->register(\SalKhimani\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/tokenAccessTokenControllerissueToken-GET/tokensAuthorizedAccessTokenControllerforUserauthDELETE/tokens/{token\_id}AuthorizedAccessTokenControllerdestroyauthPOST/token/refreshTransientTokenControllerrefreshauthGET/clientsClientControllerforUserauthPOST/clientsClientControllerstoreauthPUT/clients/{client\_id}ClientControllerupdateauthDELETE/clients/{client\_id}ClientControllerdestroyauthGET/scopesScopeControllerallauthGET/personal-access-tokensPersonalAccessTokenControllerforUserauthPOST/personal-access-tokensPersonalAccessTokenControllerstoreauthDELETE/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 [
	'oauth_prefix' => env('API_OAUTH_PREFIX', 'api/oauth')
];
```

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 SalKhimani\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 SalKhimani\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

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

2448d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/574b5b0c6ca90c931fe2e3f4bf9f6a9c71d246fc74ed1f9a7b36d8004d476409?d=identicon)[thesalmankhimani](/maintainers/thesalmankhimani)

---

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)")[![thesalmankhimani](https://avatars.githubusercontent.com/u/1826699?v=4)](https://github.com/thesalmankhimani "thesalmankhimani (5 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/thesalmankhimani-lumen-passport-mongodb/health.svg)

```
[![Health](https://phpackages.com/badges/thesalmankhimani-lumen-passport-mongodb/health.svg)](https://phpackages.com/packages/thesalmankhimani-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)
