Unfortunately, this project has been discontinued

JWT Auth Installation

Installation instructions for JWT Authentication

Install tymon/jwt-auth

Require the package using composer:

composer require tymon/jwt-auth:^[email protected]

Add the service provider in config/app.php

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

Publish the vendor config file:

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

Generate the JWT

php artisan jwt:secret

 

Install irazasyed/jwt-auth-guard

Require the package using composer:

composer require irazasyed/jwt-auth-guard

Add the service provider in config/app.php

Irazasyed\JwtAuthGuard\JwtAuthGuardServiceProvider::class,

Setup the Guard driver in your config/auth.php

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

Update unauthorized format

We still need to update the format of the authorized response to match our response macros.

Replace the unauthenticated method in app/Exceptions/Handler.php with the below:

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->error('Unauthenticated.', 401);
    }

    return redirect()->guest(route('login'));
}

You're all set!