- Lumen Version : 5.8.12
- tymon/jwt-auth Version : dev-develop
- Clone the repo :
git clone https://github.com/refdinal22/api_sikoma.git
- Enter the project :
cd api_sikoma
- Install composer dependency for current project :
composer install
- Copy file .env.example, and then paste it as .env, and then set your .env file
- Generate APP key :
php artisan key:generate
- Generate Tymon JWT secret key, the secret will be found in .env file variable JWT_SECRET :
php artisan jwt:secret
- Migrate the database :
php artisan migrate
- Serve lumen project :
php -S localhost:8000 -t public
- AuthController is used for register and login user
- UserController is used to demonstrate some action guarded with auth middleware (Need valid token to access)
- To see user information by provided token, check UserController@profile
- The configuration file for authentication is in config/auth.php, as for token is in config/jwt.php
- To change token expiration time, change
'ttl' => env('JWT_TTL', MINUTES)
in config/jwt.php, the default is 60 minutes
https://dev.to/ndiecodes/build-a-jwt-authenticated-api-with-lumen-2afm