PHPackages                             sim1barreto/passport-custom-request-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. sim1barreto/passport-custom-request-grant

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

sim1barreto/passport-custom-request-grant
=========================================

Custom Request Grant for Laravel Passport

0587PHP

Since Jun 8Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Install
-------

[](#install)

Install with composer... `composer require mikemclin/passport-custom-request-grant`

### Versions

[](#versions)

- Laravel 5.4 - Use version `^1.0`
- Laravel 5.3 - Use version `^0.1`

Setup
-----

[](#setup)

- Add `MikeMcLin\Passport\CustomRequestGrantProvider` to your list of providers **after** `Laravel\Passport\PassportServiceProvider`.
- Add `byPassportCustomRequest($request)` method to your `User` model (or whatever model you have configured to work with Passport).
    - The method should accept an `Illuminate\Http\Request` object.
    - You should authorize and retrieve user based on this request
    - If you find that the request met your requirement, return the User model.
    - If the request did not satisfy your requirement, return `null`

How to use
----------

[](#how-to-use)

- Make a **POST** request to `https://your-site.com/oauth/token`, just like you would a **Password** or **Refresh** grant.
- The POST body should contain `grant_type` = `custom_request`.
- The request will get routed to your `User::byPassportCustomRequest()` function, where you will determine if access should be granted or not.
- An `access_token` and `refresh_token` will be returned if successful.

### Example

[](#example)

Here is what a `User::byPassportCustomRequest()` method might look like...

```
/**
 * Verify and retrieve user by custom token request.
 *
 * @param \Illuminate\Http\Request $request
 *
 * @return \Illuminate\Database\Eloquent\Model|null
 * @throws \League\OAuth2\Server\Exception\OAuthServerException
 */
public function byPassportCustomRequest(Request $request)
{
    try {
        if ($request->get('sso_token')) {
            return $this->bySsoToken($request->get('sso_token'));
        }
    } catch (\Exception $e) {
        throw OAuthServerException::accessDenied($e->getMessage());
    }
    return null;
}
```

In this example, the app is able to authenticate a user based on an `sso_token` property from a submitted JSON payload. The `bySsoToken` is this app's way of doing that. It will return `null` or a user object. It also might throw exceptions explaining why the token is invalid. The `byPassportCustomRequest` catches any of those exceptions and converts them to appropriate OAuth exception type. If an `ssoToken` is not present on the request payload, then we return `null` which returns an **invalid\_credentials** error response:

```
{
  "error": "invalid_credentials",
  "message": "The user credentials were incorrect."
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 52.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ea1dc7440fba230e2ab0c594dbe4840c14d0d91a039e42ea24285158a335df2?d=identicon)[sim1barreto](/maintainers/sim1barreto)

---

Top Contributors

[![mikemclin](https://avatars.githubusercontent.com/u/1570155?v=4)](https://github.com/mikemclin "mikemclin (9 commits)")[![sim1barreto](https://avatars.githubusercontent.com/u/97276428?v=4)](https://github.com/sim1barreto "sim1barreto (5 commits)")[![jmancusi](https://avatars.githubusercontent.com/u/645563?v=4)](https://github.com/jmancusi "jmancusi (2 commits)")[![EricTendian](https://avatars.githubusercontent.com/u/498525?v=4)](https://github.com/EricTendian "EricTendian (1 commits)")

### Embed Badge

![Health badge](/badges/sim1barreto-passport-custom-request-grant/health.svg)

```
[![Health](https://phpackages.com/badges/sim1barreto-passport-custom-request-grant/health.svg)](https://phpackages.com/packages/sim1barreto-passport-custom-request-grant)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
