Build authentication into your Laravel API with JSON Web Tokens (JWT)

Connor Leech
Employbl
Published in
6 min readDec 12, 2018

--

tymondesigns/jwt-auth

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' =>…

--

--

Connor Leech
Employbl

Girl Dad x 2. Cofounder @Employbl. Software Engineer @CommentSold.