Build authentication into your Laravel API with JSON Web Tokens (JWT)
In this tutorial we’re going to expand the API we built in the previous tutorial to include authentication. By default Laravel includes authentication for session based authentication. Check it out by looking at the Laravel docs on authentication:
At its core, Laravel’s authentication facilities are made up of “guards” and “providers”. Guards define how users are authenticated for each request. For example, Laravel ships with a
session
guard which maintains state using session storage and cookies. — Laravel 5.7 Authentication docs
Source code for what we’re working on
We can see the config for session based authentication under the “guards” section of config/auth.php:
/*
|-------------------------------------------------------------------
| Authentication Guards
|-------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
...'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' =>…