PHPackages                             binarygeotech/passport-booster - 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. binarygeotech/passport-booster

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

binarygeotech/passport-booster
==============================

Adds multiple authentication functionality to Laravel Passport

28PHP

Since Apr 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/binarygeotech/passport-booster)[ Packagist](https://packagist.org/packages/binarygeotech/passport-booster)[ RSS](/packages/binarygeotech-passport-booster/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

Passport Booster
================

[](#passport-booster)

This package extends Laravel Passport functionalities by enabling you to use multiple User Models (Authentication Guard). A middleware which enables multi-auth is included and registered automatically as `passport.guard`.

\#Installation `composer require binarygeotech/passport-booster`

Setup
=====

[](#setup)

- Add `passport.guard` to Laravel Passport's routes setup in the boot method of `AuthServiceProvider.php` file.

```
use Laravel\Passport\Passport; // Import Laravel Passport
use BGS\PassportBooster\PassportBooster; // Import Passport Booster

public function boot()
{
	...
	Passport::routes(
		null,
		[
			'middleware' => [
				'passport.guard'
			]
		]
	);

	PassportBooster::enableMultiGuard(true); // Add this line to enable Multiple Authentication Guard feature.

	...
}

```

Usage
=====

[](#usage)

- Setup your guards in your `config/auth.php`

```
'guards' => [
    ...
    'admin' => [
        'driver' => 'passport',
        'provider' => 'admins',
        'hash' => false,
    ],
	'clients' => [
        'driver' => 'passport',
        'provider' => 'clients',
        'hash' => false,
    ],
],

'providers' => [
    ...
    'admins' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
	'clients' => [
        'driver' => 'eloquent',
        'model' => App\Clients::class,
    ],
],

```

- Add wrap your api routes in a group with `passport.guard:{guard}` middleware

Example below

```
	// Admin Route
	Route::group(
		[
			'prefix' => 'administrator',
			'middleware' => [
				'passport.guard:admin'
			]
		],
		function () {
			/*
				Using the proxy token generation method as documented here https://laravel.com/docs/7.x/passport#requesting-password-grant-tokens,
				use the route below.
			*/
			Route::post('/access/login', 'Auth\AdminLoginController@login')
				->name('api.admin.login');

			// Define other routes by applying the guard middleware
			Route::group(
				[
					'middleware' => [
						'auth:admin',
					],
				],
				function () {
					Route::get('profile', 'Auth\AdminLoginController@profile')->name('api.admin.profile');

				}

			)
		}
	);

	// Client Route
	Route::group(
		[
			'prefix' => 'client',
			'middleware' => [
				'passport.guard:client'
			]
		],
		function () {
			/*
				Using the proxy token generation method as documented here https://laravel.com/docs/7.x/passport#requesting-password-grant-tokens,
				use the route below.
			*/
			Route::post('/access/login', 'Auth\ClientLoginController@login')
				->name('api.client.login');

			// Define other routes by applying the guard middleware
			Route::group(
				[
					'middleware' => [
						'auth:client',
					],
				],
				function () {
					Route::get('profile', 'Auth\ClientLoginController@profile')->name('api.client.profile');

				}

			)
		}
	);

```

- Add `guard` parameter to all your token requests (`oauth/token` or using guzzle)

Guzzle Example ()

```
$http = new GuzzleHttp\Client;

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'username' => 'taylor@laravel.com',
        'password' => 'my-password',
        'scope' => '',
		'guard' => 'admin'
    ],
]);

return json_decode((string) $response->getBody(), true);

```

Additional Customisation
========================

[](#additional-customisation)

- Extending class files, publish the configration file `php artisan vendor:publish --tag=passport-booster-config`

```
