yutiandev/laravel-passport-multiauth

Laravel passport multiple user authentication

0.1.0 2018-03-31 09:17 UTC

This package is auto-updated.

Last update: 2024-04-06 18:02:04 UTC


README

License

Add multi-authentication support to Laravel Passport

Installation

With Composer

$ composer require yutiandev/laravel-passport-multiauth

If you are using a Laravel version less than 5.5 you need to add the provider on config/app.php:

    'providers' => [
        ...
        YTDev\LPM\MultiAuthServiceProvider::class,
    ]

Configuration

And your config/auth.php providers

Example:

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model'  => App\User::class,
            'client_id' => 2,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model'  => App\Admin::class,
            'client_id' => 4, 
        ]  
    ]

Usage

Request

Add application/vnd.passport.provider_name to the HTTP Accept header

Example:

GET /user HTTP/1.1

Host: example.com
X-Requested-With: XMLHttpRequest
Accept: application/json; application/vnd.passport.admins
Authorization: Bearer [TOKEN]

Token

Example:

public function token()
{
    $client = new GuzzleHttp\Client();
    
    $response = $http->post('http://your-app.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => \YTDev\LPM\Facades\PassportMultiAuth::clientId(),
            'client_secret' => 'client-secret',
            'username' => 'taylor@laravel.com',
            'password' => 'my-password',
            'scope' => '',
        ],
    ]);
    
    return json_decode((string) $response->getBody(), true);
}