PHPackages                             clystnet/laravel-jwt - 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. clystnet/laravel-jwt

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

clystnet/laravel-jwt
====================

A jwt package for reisssuing token purpose based on jwt-auth package. This is a fork of the unisharp/laravel-jwt package.

0.4.4(1y ago)077MITPHPPHP ^7.1 | ^8.0

Since Nov 8Pushed 1y agoCompare

[ Source](https://github.com/Exe-Squared/laravel-jwt)[ Packagist](https://packagist.org/packages/clystnet/laravel-jwt)[ RSS](/packages/clystnet-laravel-jwt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (25)Used By (0)

Laravel JWT
===========

[](#laravel-jwt)

**This is a fork of the UniSharp/laravel-jwt package**

Approach
--------

[](#approach)

If you pick `Tymon JWTAuth` as your jwt solution in your project, when you try to refresh your token, the package will blacklist your exchanged token (assume your blacklist feature is enabled). So when your client faces a concurrency use case, your request might be rejected because that request is sent before your app renews jwt token returned by server. This package caches the refreshed jwt token in a short period to ensure your client side can get correct response even if your request carries an old token in a concurrency case.

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

[](#installation)

- Via Composer

```
composer require clystnet/laravel-jwt

```

- Add the Service Provider

```
PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider::class,
Clystnet\JWT\JWTServiceProvider::class,
```

> In Lumen please use `PHPOpenSourceSaver\JWTAuth\Providers\LumenServiceProvider::class,`

Next, also in the app.php config file, under the aliases array, you may want to add the JWTAuth facade.

```
'JWTAuth' => 'PHPOpenSourceSaver\JWTAuth\Facades\JWTAuth',
'JWTFactory' => 'PHPOpenSourceSaver\JWTAuth\Facades\JWTFactory'

```

Finally, you will want to publish the config using the following command:

```
php artisan vendor:publish --provider="PHPOpenSourceSaver\JWTAuth\Providers\JWTAuthServiceProvider"
php artisan vendor:publish --provider="Clystnet\JWT\JWTServiceProvider"

```

Don't forget to set a secret key in the config file!

```
$ php artisan jwt:secret

```

this will generate a new random key, which will be used to sign your tokens.

And you're done!

Usage
-----

[](#usage)

Open your `config/auth.php` config file and in place of driver under any of your guards, just add the `jwt-auth` as your driver and you're all set. Make sure you also set `provider` for the guard to communicate with your database.

### Setup Guard Driver

[](#setup-guard-driver)

```
// config/auth.php
'guards' => [
    'api' => [
        'driver' => 'jwt-auth',
        'provider' => 'users'
    ],

    // ...
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
    ],
],
```

### Middleware Usage

[](#middleware-usage)

Middleware protecting the route:

```
Route::get('api/content', ['middleware' => 'laravel.jwt', 'uses' => 'ContentController@content']);
```

Middleware protecting the controller:

```
