PHPackages                             kslimani/laravel-passport-grant - 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. kslimani/laravel-passport-grant

ActiveLibrary

kslimani/laravel-passport-grant
===============================

Laravel Passport custom grant types provider

1.1.0(6y ago)1429.9k↓40.2%4[1 issues](https://github.com/kslimani/laravel-passport-grant/issues)1MITPHPPHP &gt;=7.0

Since May 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kslimani/laravel-passport-grant)[ Packagist](https://packagist.org/packages/kslimani/laravel-passport-grant)[ RSS](/packages/kslimani-laravel-passport-grant/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

[![](https://github.com/kslimani/laravel-passport-grant/workflows/Integration%20tests/badge.svg)](https://github.com/kslimani/laravel-passport-grant/workflows/Integration%20tests/badge.svg) [![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)

laravel-passport-grant
======================

[](#laravel-passport-grant)

This library provide a very simple way to add **custom grant types** for [Laravel Passport](https://github.com/laravel/passport) OAuth2 server.

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 kslimani/laravel-passport-grant
```

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

```
php artisan vendor:publish --provider="Sk\Passport\GrantTypesServiceProvider" --tag="config"
```

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

[](#configuration)

In your [config/passportgrant.php](https://github.com/kslimani/laravel-passport-grant/blob/master/config/passportgrant.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' => [
    // 'acme' => 'App\Passport\AcmeUserProvider',
],
```

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 `Sk\Passport\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/kslimani/laravel-passport-grant/blob/master/src/UserProvider.php) class provide methods to validate and retrieve request custom parameters.

Therefore, creating a user provider becomes simple :

```
