Download the PHP package hamedov/passport-multiauth without Composer
On this page you can find all versions of the php package hamedov/passport-multiauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hamedov/passport-multiauth
More information about hamedov/passport-multiauth
Files in hamedov/passport-multiauth
Package passport-multiauth
Short Description Multiauth and custom grants for laravel passport
License MIT
Informations about the package passport-multiauth
Passport multiauth
This package simply enables you to authenticate models other than App\User using laravel passport.
Note: Starting from version 9.x multiauth is built in in laravel passport, therefore this package is usable until version 8.x. If you still need the custom grants feature please use this package: https://github.com/hamedov93/passport-grants
Installation
composer require hamedov/passport-multiauth
- This package overrides
PassportServiceProvider
, so you should remove it from config/app.php providers section.
Usage
-
Add your guards and providers to config/auth.php
-
Add
guard
parameter to your token request
Example using guzzle http -
Authenticate your models using auth middleware with the desired guard as follows:
- No extra parameters required for refresh token requests.
- Of course all models must extend
Illuminate\Foundation\Auth\User
and useLaravel\Passport\HasApiTokens
Trait. - That's all.
Revoke access token
Warning
- Relationships that depend on
oauth_access_tokens
table such as$user->tokens()
and$token->user();
are not yet implemented for multiauth and won't work, You wouldn't need them anyway. However they will be implemented in a future release.
Custom grants:
- Create a new custom grant:
We will be using facebook login as an example here
This will create a new grant class in App\Grants folder
-
Specify unique identifier for your grant
- Specify The parameters you will be sending in access token request for user authentication instead of username and password
The access token request should look like this:
- Next add your authentication logic to
getUserEntityByRequestParams
method
You will receive an empty instance of the authenticated model as first parameter.
The second parameter is an associative array containing values of parameters specified in request_params
property.
-
The method implementation should be something like this:
- You can use the previous example for any authenticatable entity without any difference, you just need to provide the guard parameter in token request and implement your authentication logic and return void/false if authentication fails or an instance of Laravel\Passport\Bridge\User for success.
License
Released under the Mit license, see LICENSE