PHPackages                             dkrasov/jwt-auth-guard - 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. dkrasov/jwt-auth-guard

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

dkrasov/jwt-auth-guard
======================

JWT Auth Guard for Laravel and Lumen

v1.0.4(10y ago)01.5kMITPHPPHP &gt;=5.5.0

Since Jan 24Pushed 5y agoCompare

[ Source](https://github.com/dkrasov/jwt-auth-guard)[ Packagist](https://packagist.org/packages/dkrasov/jwt-auth-guard)[ Docs](https://github.com/irazasyed/laravel-jwt-guard)[ RSS](/packages/dkrasov-jwt-auth-guard/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

JWT Auth Guard
==============

[](#jwt-auth-guard)

[![Join PHP Chat](https://camo.githubusercontent.com/29f67fb2289efd1ecede6eaa41c82be0e3f93dbf5a8193f1f0fc1b4f33719fa7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536c61636b2d504850253230436861742d3563366161612e7376673f7374796c653d666c61742d737175617265266c6f676f3d736c61636b266c6162656c436f6c6f723d344131353442)](https://phpchat.co/?ref=jwt-auth-guard)[![Chat on Telegram](https://camo.githubusercontent.com/c793b6d887d39dac6773fa734b19b63fb1b8a392156528c648c2564000509eba/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4050485043686174436f2d3243413545302e7376673f7374796c653d666c61742d737175617265266c6f676f3d74656c656772616d266c6162656c3d54656c656772616d)](https://t.me/PHPChatCo)[![Laravel Package](https://camo.githubusercontent.com/f3202343dd975ed499e2aacf279c8ad742599e51b866c73d2677afb11ad57e73/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d35253743362d4646324432302e7376673f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6162656c436f6c6f723d626c61636b266c6f676f436f6c6f723d7768697465)](https://github.com/irazasyed/jwt-auth-guard)[![Latest Version on Packagist](https://camo.githubusercontent.com/f57b9d11a49a016e31363b1c636f5c3247e0653d971891dc46ce18bd2ec6a6c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6972617a61737965642f6a77742d617574682d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/irazasyed/jwt-auth-guard)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/15f05aa59ec8ba3251d840b2da62efd305a1b44253c7fe917fed33afca096d4b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6972617a61737965642f6a77742d617574682d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/irazasyed/jwt-auth-guard)

> JWT Auth Guard is a Laravel &amp; Lumen Package that lets you use `jwt` as your driver for authentication guard in your application.
>
> The Guard uses `tymon/jwt-auth` package for authentication and token handling.

Requirements
------------

[](#requirements)

- Laravel or Lumen Installation.
- [tymon/jwt-auth](https://github.com/tymondesigns/jwt-auth) `^1.0@dev` Package Setup and Config'd.

Pre-Installation
----------------

[](#pre-installation)

First install and setup [tymon/jwt-auth](https://github.com/tymondesigns/jwt-auth) package.

```
$ composer require tymon/jwt-auth:^1.0@dev
```

Once done, config it and then install this package.

Install
-------

[](#install)

Via Composer

```
$ composer require irazasyed/jwt-auth-guard
```

### Add the Service Provider

[](#add-the-service-provider)

#### Laravel

[](#laravel)

Open `config/app.php` and, to your `providers` array at the bottom, add:

```
Irazasyed\JwtAuthGuard\JwtAuthGuardServiceProvider::class
```

#### Lumen

[](#lumen)

Open `bootstrap/app.php` and register the service provider:

```
$app->register(Irazasyed\JwtAuthGuard\JwtAuthGuardServiceProvider::class);
```

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' => 'auth:api', 'uses' => 'ContentController@content']);
```

Middleware protecting the controller:

```
