2017 © Pedro Peláez
 

library laraveljwt

Package Jwt Laravel

image

brenodouglas/laraveljwt

Package Jwt Laravel

  • Friday, March 11, 2016
  • by breninho94
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Installation

1. Depedency

Using composer, execute the following command to automatically update your composer.json:, (*1)

composer require brenodouglas/laraveljwt

or manually update your composer.json file, (*2)

{
    "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:, (*3)

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

3. Publishing configuration file

To publish the default configuration file, (*4)

php artisan vendor:publish

4. Using the middleware

To protect your routes, you can use the built-in middlewares., (*5)

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:, (*6)

$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:, (*7)

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

One example route auth and protected route with jwt:, (*8)

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:, (*9)

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

The return is json with a key 'token'., (*10)

The Versions

11/03 2016

dev-master

9999999-dev

Package Jwt Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Breno Douglas

11/03 2016

0.2

0.2.0.0

Package Jwt Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Breno Douglas

10/03 2016

0.1

0.1.0.0

Package Jwt Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Breno Douglas