Simple way create API with authorization with JWT
- Cope config file:
cp .env.example .env
- Config .env:
- Set param "APP_KEY" with random string (32 characters long)
- Set param "JWT_SECRET" with random string too (used for JWT, recommended 32 characters long)
- Config database config (DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD)
- Run install dependencies:
composer install
- Run migration database:
php artisan migrate
- Insert data to DB
php artisan db:seed
(insert users in database, see database/factories/ModelFactory.php)
We have private access to the list of users, you can check by typing in the browser:
http://lumen-jwt.loc/users
And you see fail message:
"error": "Token not provided."
- Select any user from database (email, password)
- Go to postman (https://www.getpostman.com/)
- Create POST request to url: https://lumen-jwt.loc/auth/lohin with params:
- password
- Return token, save it
- Create GET request to url: https://lumen-jwt.loc/users with param:
- token (obtained with successful login)
- See result: list of users