Setting up JWT authentication
Now we have to set up the JSON web token authentication with our Laravel app so that we can host our frontend separately from our backend. To do that, we use the tymon/jwt-auth
library. To install it, we run the following command:
composer require tymon/jwt-auth
Next, we run the following command to publish the package configuration files:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
The preceding command will add all the required configuration for us. We should now have config/jwt.php
added to our app. Then we generate the secret key to sign the JSON web token by running the following command:
php artisan jwt:secret
The secret
key will be added to the .env
file with the key JWT_SECRET
.
Configuring our authentication
Next, we have to configure our authentication so that we can verify our JSON web token before we can successfully make a request to routes that requires authentication...