PHPackages                             jsdecena/laravel-passport-multiauth - 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. [Framework](/categories/framework)
4. /
5. jsdecena/laravel-passport-multiauth

ActiveProject[Framework](/categories/framework)

jsdecena/laravel-passport-multiauth
===================================

Simple laravel passport multiple user authentication

v0.2.4(8y ago)501.1k17[2 issues](https://github.com/jsdecena/laravel-passport-mutiauth/issues)MITPHP

Since Oct 12Pushed 7y ago5 watchersCompare

[ Source](https://github.com/jsdecena/laravel-passport-mutiauth)[ Packagist](https://packagist.org/packages/jsdecena/laravel-passport-multiauth)[ RSS](/packages/jsdecena-laravel-passport-multiauth/feed)WikiDiscussions master Synced 3w ago

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

Laravel Passport Multi-Authentication middleware
================================================

[](#laravel-passport-multi-authentication-middleware)

[![Latest Stable Version](https://camo.githubusercontent.com/52f6cfd49dff0befbb8fa2c46f4d394179ea27c0cd7dc0fbe2a2c161be383036/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f6c61726176656c2d70617373706f72742d6d756c7469617574682f762f737461626c65)](https://packagist.org/packages/jsdecena/laravel-passport-multiauth)[![Total Downloads](https://camo.githubusercontent.com/9487431eeb5ef38f0488857ed3ed23d36e8652255edf23bbafceb1c54a890561/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f6c61726176656c2d70617373706f72742d6d756c7469617574682f646f776e6c6f616473)](https://packagist.org/packages/jsdecena/laravel-passport-multiauth)[![License](https://camo.githubusercontent.com/e641e778397eefc7495a76012c62436493f3c044724c2ba287e6b7d0201ce840/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f6c61726176656c2d70617373706f72742d6d756c7469617574682f6c6963656e7365)](https://packagist.org/packages/jsdecena/laravel-passport-multiauth)

#### Laravel passport default behavior is to authenticate your `user` on the `users` table.

[](#laravel-passport-default-behavior-is-to-authenticate-your-user-on-the-users-table)

#### While this is good enough for most of the apps, sometimes we need to tweak it a little bit if there is a new need arises.

[](#while-this-is-good-enough-for-most-of-the-apps-sometimes-we-need-to-tweak-it-a-little-bit-if-there-is-a-new-need-arises)

#### I created this middleware because I need a few user groups that would access the app and in every user group there are roles.

[](#i-created-this-middleware-because-i-need-a-few-user-groups-that-would-access-the-app-and-in-every-user-group-there-are-roles)

How to install
==============

[](#how-to-install)

- In your terminal, run `composer require jsdecena/laravel-passport-multiauth` or add this in your `composer.json`

```
    "require": {
        ...
        "jsdecena/laravel-passport-multiauth": "^0.2",
        ...
    },

```

- Add this line in your `config/app.php`

```
	'providers' => [
	    ...
	    Jsdecena\LPM\LaravelPassportMultiAuthServiceProvider::class,
	    ...
	]

```

- Add this in your `app\Http\Kernel.php`

```
    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        ...
        'mmda' => \Jsdecena\LPM\Middleware\ProviderDetectorMiddleware::class,
    ];

```

- Also in your `routes/api.php`

```
    Route::post('oauth/token/', 'CustomerTokenAuthController@issueToken')
        ->middleware(['mmda', 'throttle'])
        ->name('issue.token');

```

> Trivia: Why mmda? This is because in the Philippines, they are the one that handles the traffic 😅

- And in the `config/auth.php`

```
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

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

        'customers' => [
            'driver' => 'passport',
            'provider' => 'customers'
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => 'App\User',
        ],
        /**
         * This is the important part. You can create as many providers as you like but right now,
         * we just need the customer
         */
         'customers' => [
             'driver' => 'eloquent',
             'model' => 'App\Customer',
         ],
    ],

```

> In your controller, you can access the user logged in via `auth()->guard('customer')->user()`

- Your `Customer` model should extend with `Authenticatable` and use the `Notifiable` and `HasApiTokens` traits

```
