PHPackages                             imrancse/passportgrant - 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. imrancse/passportgrant

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

imrancse/passportgrant
======================

Custom grant\_type for laravel passport

0858PHP

Since Nov 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/imrancse94/passport-custom-grant-type)[ Packagist](https://packagist.org/packages/imrancse/passportgrant)[ RSS](/packages/imrancse-passportgrant/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Installation
------------

[](#installation)

Note: this documentation assumes [Laravel Passport installation](https://laravel.com/docs/master/passport#introduction) is completed.

To get started, install package via the Composer package manager :

```
composer require imrancse/passportgrant
```

Publish the `passport_grant_type.php` configuration file using `vendor:publish` Artisan command :

```
php artisan vendor:publish --provider="imrancse\passportgrant\PassportGrantServiceProvider" --tag="config"
```

Configuration
-------------

[](#configuration)

In your [config/passport\_grant\_type.php](https://github.com/imrancse94/passport-custom-grant-type/blob/master/config/passport_grant_type.php) configuration file, enable any custom grant types providing user provider class.

```
// "grants" is an array of user provider class indexed by grant type

'grants' => [
    // 'otp_grant' => 'App\Passport\OTPGrantProvider',
],
```

User provider
-------------

[](#user-provider)

User provider class roles are :

- validate `/oauth/token` request custom parameters
- provide user entity instance

User provider class must implements the `imrancse\passportgrant\UserProviderInterface` :

```
/**
 * Validate request parameters.
 *
 * @param  \Psr\Http\Message\ServerRequestInterface  $request
 * @return void
 * @throws \League\OAuth2\Server\Exception\OAuthServerException
 */
public function validate(ServerRequestInterface $request);

/**
 * Retrieve user instance from request.
 *
 * @param  \Psr\Http\Message\ServerRequestInterface  $request
 * @return mixed|null
 */
public function retrieve(ServerRequestInterface $request);
```

If request validation fails, the `validate()` method must throw a `League\OAuth2\Server\Exception\OAuthServerException` invalid parameter exception.

On success, the `retrieve()` method must return a `League\OAuth2\Server\Entities\UserEntityInterface` or `Illuminate\Contracts\Auth\Authenticatable` instance. Otherwise `null` on failure.

User provider example
---------------------

[](#user-provider-example)

For convenience, the [UserProvider](https://github.com/imrancse94/passport-custom-grant-type/blob/master/src/UserProvider.php) class provide methods to validate and retrieve request custom parameters.

Therefore, creating a user provider becomes simple :

```
