This project simulate how JWT Server run in Laravel and NodeJS + Express in a simple way
http://docs.jwtapi3.apiary.io/#
- PHP 7.0
- Composer 1.4.3
- NPM 3.10.10
- NodeJs 6.11.3
- MySQL / MariaDB
- Postman for Test the API
- Clone this repository to your machine
-
Open terminal inside project folder.
-
Move to laravel directory
cd laravelBackend54
- Install dependencies by type
composer install
-
Copy (
.env.example
) file into (.env
) (Create a new file named .env). -
Create a database on your MySQL Server
-
Open (
.env
) file and change the database configs likeDB_DATABASE
,DB_USERNAME
, andDB_PASSWORD
to match your system database environment. -
Run
php artisan key:generate
in terminal to set the application APP_KEY
.
- Run
php artisan vendor:publish --provider="Codecasts\Auth\JWT\ServiceProvider"
in terminal to publish Codecast Laravel JWT
- Generate secret key by
php artisan jwt:generate
and then copy generated secret from terminal into (.env
) file , usually put on last line
JWT_SECRET=GENERATED KEY FROM TERMINAL
-
Run Migration
php artisan migrate
-
Run development server
php artisan serve
orphp artisan serve --port=PORT
for custom port
-
Open terminal inside project folder.
-
Move to express directory
cd expressBackend
- Install dependencies by type
npm install
- Setup the secret key
open (index.js
) and change the value of variable var secret
from secret key generated on laravel application but exclude the base64:
Example :
Secret from laravel (.env
) is base64:FClidjjWPImBqjptbZWc4XCtq9F0P7PUBnBBLTpf6ew=
Copy to (index.js
) only FClidjjWPImBqjptbZWc4XCtq9F0P7PUBnBBLTpf6ew=
var express = require('express');
var app = express();
var jwt = require('jwt-simple');
//change first parameter of Buffer.from to match laravel server jwt secret exclude the 'base64:'
var secret = Buffer.from('FClidjjWPImBqjptbZWc4XCtq9F0P7PUBnBBLTpf6ew=', 'base64')
- open terminal and run the server by type
node index.js
Currently unit testing just available for LaravelServer
to run test type vendor/bin/phpunit
on (laravelBackend54
) folder