brenodouglas/laraveljwt

Package Jwt Laravel
17 1
Install
composer require brenodouglas/laraveljwt
Latest Version:0.2
License:MIT
Last Updated:Mar 11, 2016
Links: GitHub  ·  Packagist
Maintainer: breninho94

Installation

1. Depedency

Using composer, execute the following command to automatically update your composer.json:

composer require brenodouglas/laraveljwt

or manually update your composer.json file

{
    "require": {
        "brenodouglas/laraveljwt": "^0.1.0"
    }
}

2. Provider

You need to update your application configuration in order to register the package, so it can be loaded by Laravel. Just update your config/app.php file adding the following code at the end of your 'providers' section:

// file START ommited
    'providers' => [
        // other providers ommited
        \LaravelJwt\JwtProvider::class,
    ],
// file END ommited

3. Publishing configuration file

To publish the default configuration file

php artisan vendor:publish

4. Using the middleware

To protect your routes, you can use the built-in middlewares.

Verify token and regenerate new token in get or header with key 'access-token' : authjwt
Route::get('foo', ['middleware' => ['authjwt'], function()
{
    return 'Yes I can!';
}]);

Or within controllers:

$this->middleware('authjwt');

5. Auth and Facade

Register facade and use Jwt authentication. Just update your config/app.php file adding the following code at the end of your 'aliases' section:

// file START ommited
    'aliases' => [
        // other aliases ommited
       'JWT' => \LaravelJwt\Facades\JwtAuthFacade::class
    ],
// file END ommited

One example route auth and protected route with jwt:

Route::post("auth", function(\Illuminate\Http\Request $request) {
    return response()->json(['token'=> \JWT::authenticate($request)]);
});

Route::group(['middleware' => ['authjwt']], function($router) {
    $router->get('users', function() {
        return 'Yes, a can!';
    });
});

Send POST for 'auth' route with raw body json:

{
    "email": "email@foryouruser.com",
    "password": "password"
}

The return is json with a key 'token'.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

391,429,217 4,660