Unfortunately, this project has been discontinued

Adding Authentication

This step of the tutorial covers adding Json Web Token authentication to your project.

JWT Auth setup

Assuming you've follwed the JWT installation steps, follow the instructions below to require authentication when accessing the api/posts endpoint.

Replace your previous API route with one the ways below:

routes/api.php
Route::middleware('auth:api')->get('/posts', '[email protected]');

//or

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('/posts', '[email protected]');
});

Voila! You will need to provide an Authorization header to be able to access this endpoint.

Creating tokens

Make sure to follow the JWT Usage docs in order to generate tokens, check for authentication and more.