PHPackages                             oelmenshawy/laravel-passport-user-id-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. oelmenshawy/laravel-passport-user-id-grant

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

oelmenshawy/laravel-passport-user-id-grant
==========================================

User Id Grant for Laravel Passport

01PHPCI failing

Since Jun 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/oelmenshawy/laravel-passport-user-id-grant)[ Packagist](https://packagist.org/packages/oelmenshawy/laravel-passport-user-id-grant)[ RSS](/packages/oelmenshawy-laravel-passport-user-id-grant/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Passport User Id Grant
==============================

[](#laravel-passport-user-id-grant)

This package adds a user id grant for your OAuth2 server. It can be useful if have an API and want to provide the ability for your users to return `access_token` and `refresh_token` through user id.

As a result you will be able to exchange user id to `access_token` and `refresh_token` issued by your own OAuth2 server. You will receive this user id and return the user instance that corresponds to it on your own.

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

[](#installation)

You can install this package via composer using this command:

```
composer require oelmenshawy/laravel-passport-user-id-grant
```

The package will automatically register itself.

Usage
-----

[](#usage)

Example of usage with `axios`:

```
axios.post('/oauth/token', {
    grant_type: 'user_id', // static 'user_id' value
    client_id: clientId, // client id
    client_secret: clientSecret, // client secret
    user_id: userId, // user id
  })
  .then((response) => {
    const {
      access_token: accessToken,
      expires_in: expiresIn,
      refresh_token: refreshToken,
    } = response.data;

    // success logic
  })
  .catch((error) => {
    const {
      message,
      hint,
    } = error.response.data;

    // error logic
  });
```

Example of usage with `guzzle`:

```
