Package Data | |
---|---|
Maintainer Username: | breninho94 |
Maintainer Contact: | bdouglasans@gmail.com (Breno Douglas) |
Package Create Date: | 2016-03-10 |
Package Last Update: | 2016-03-11 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-20 03:14:37 |
Package Statistics | |
---|---|
Total Downloads: | 17 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
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"
}
}
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
To publish the default configuration file
php artisan vendor:publish
To protect your routes, you can use the built-in middlewares.
Route::get('foo', ['middleware' => ['authjwt'], function()
{
return 'Yes I can!';
}]);
Or within controllers:
$this->middleware('authjwt');
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'.