Download the PHP package smartins/passport-multiauth without Composer

On this page you can find all versions of the php package smartins/passport-multiauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package passport-multiauth

[ALERT] Deprecated !!

The package is deprecated because Laravel Password has a native implementaion since version 9.0

Laravel Passport Multi-Auth

Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality StyleCI License Donate

Add multi-authentication support to Laravel Passport

Upgrading from 4.0 to 5.0

Upgrading from 2.0 to 3.0

Upgrading from 1.0 to 2.0

Compatibility

Laravel Passport
^5.0
^6.0
^7.0
^8.0
Laravel Framework Passport MultiAuth
<= 5.6 <= 3.0
5.7.x 4.0.x
>= 5.7.x <= 5.8.x 5.0.x
6.x 6.x
7.x 7.x

Installing and configuring

Install using composer:

To all works fine, we need to ensure that the SMartins\PassportMultiauth\Providers\MultiauthServiceProvider::class service provider be registered before Laravel\Passport\PassportServiceProvider::class.

Firstly, you will remove the laravel/passport package from Laravel Package Discovery.

In your composer.json file, add the laravel/passport to extra.laravel.dont-discover array:

And register the providers manually on config/app.php:

WARNING: The provider SMartins\PassportMultiauth\Providers\MultiauthServiceProvider::class MUST be added before Laravel\Passport\PassportServiceProvider::class to it works fine.

Maybe you will need clear the bootstrap cache files to re-register the providers:

Migrate database to create oauth_access_token_providers table:

NOTE If you don't ron the command to install passport run:

Instead of using the Laravel\Passport\HasApiTokens trait from Laravel Passport core, use the trait SMartins\PassportMultiauth\HasMultiAuthApiTokens.

Internally, this HasMultiAuthApiTokens uses the HasApiTokens, overriding the methods tokens() and createToken($name, $scopes = []). The behavior of the method tokens() was changed to join with the table oauth_access_token_providers getting just the tokens created to specific model. The method createToken($name, $scopes = []) was changed to create the token using the provider defined to model on config/auth.php. Now when you create the token, this token will be related with the model that is calling.

Add new provider in config/auth.php using a model that extends of Authenticatable class and use HasMultiAuthApiTokens trait.

Example:

Configure your model:

And your config/auth.php providers:

Add a new guard in config/auth.php guards array using driver passport and the provider added above:

Register the middleware AddCustomProvider to $routeMiddleware attributes on app/Http/Kernel.php file.

OBS: The param provider is required to routes wrapped by AddCustomProvider middleware. You must to pass a valid provider configured on config/auth.php.

Add new middleware Authenticate on app/Http/Kernel $routeMiddleware attribute.

Encapsulate the passport routes for access token with the registered middleware in AuthServiceProvider. This middleware will add the capability to Passport route oauth/token use the value of provider param on request:

Optional: Publish migrations:

Just run the vendor:publish artisan command with package provider as parameter:

If you are not going to use PassportMultiauth's default migrations, you should call the SMartins\PassportMultiauth\PassportMultiauth::ignoreMigrations method in the register method of your AppServiceProvider.

Usage

Add the provider parameter in your request at /oauth/token:

You can pass your guards on multiauth middleware as you wish. Example:

The api guard use is equals the example with admin.

You can pass many guards to multiauth middleware.

You can use too the Auth facade:

Refreshing tokens

Add the provider parameter in your request at /oauth/token:

Using scopes

Just use the scope and scopes middlewares from Laravel\Passport.

Personal Access Tokens

In your model that uses the trait SMartins\PassportMultiauth\HasMultiAuthApiTokens you can uses the methods createToken($name, $scopes = []) and tokens() to manage your personal access tokens. E.g.:

Known Issues

To all works correctly you must use the default guard web on config/auth.php. E.g.:

Exists an opened issues that will be analysed ASAP.

Unit tests

Instead to use the Laravel\Passport\Passport::actingAs() method, use SMartins\PassportMultiauth\PassportMultiauth::actingAs(). The difference is that the actingAs from this package get the guard based on Authenticatable instance passed on first parameter and authenticate this user using your guard. On authenticated request (Using auth middleware from package - SMartins\PassportMultiauth\Http\Middleware\MultiAuthenticate) the guard is checked on Request to return the user or throws a Unauthenticated exception. E.g.:

Sample Project

You can see a complete Passport-Multiauth implementation using Password Grant Tokens and Personal Access Token on passport-multiauth-demo project

Contributors

Based on renanwilian responses to Passport Multi-Auth issue.


All versions of passport-multiauth with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
laravel/passport Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package smartins/passport-multiauth contains the following files

Loading the files please wait ....