Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.97 KB

README.md

File metadata and controls

35 lines (27 loc) · 1.97 KB

Lumen jwt authentication

  • Lumen Version : 5.8.12

Package added :

  • tymon/jwt-auth Version : dev-develop

Use the project

  • 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

Hint

  • 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

Register

alt text

Login

alt text

Access guarded route

alt text

Reference

https://dev.to/ndiecodes/build-a-jwt-authenticated-api-with-lumen-2afm