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

ActiveLibrary

zoran-wang/jwt-auth-guard
=========================

jwt auth guard for laravel or lumen ,the version 5+

0.0.1.x-dev(8y ago)038[1 issues](https://github.com/ZoranWong/JWTAuthGuard/issues)MITPHPPHP &gt;=7.0.0

Since Apr 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ZoranWong/JWTAuthGuard)[ Packagist](https://packagist.org/packages/zoran-wang/jwt-auth-guard)[ RSS](/packages/zoran-wang-jwt-auth-guard/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

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

[](#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) `^0.5.12` 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:^0.5.12
```

Once done, config it and then install this package.

Install
-------

[](#install)

Via Composer

```
$ composer require zoran-wang/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:

```
Zoran\JwtAuthGuard\JwtAuthGuardServiceProvider::class
```

#### Lumen

[](#lumen)

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

```
$app->register(Zoran\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,
    ],
    'users' => [
        'driver' => 'database',
        'table'  => 'users',
    ],
    'users' => [
        'driver' => 'repository',
        'repository'  => App\Repositories\UserEloquentRepository::class,
    ],
],
```

### Middleware Usage

[](#middleware-usage)

Middleware protecting the route:

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

Middleware protecting the controller:

```
