Coder Social home page Coder Social logo

jwtbackends's Introduction

JWTBackends

Introduction

This project simulate how JWT Server run in Laravel and NodeJS + Express in a simple way

API Documentation

http://docs.jwtapi3.apiary.io/#

Requirements

  • PHP 7.0
  • Composer 1.4.3
  • NPM 3.10.10
  • NodeJs 6.11.3
  • MySQL / MariaDB
  • Postman for Test the API

Installations

  • Clone this repository to your machine

Laravel Server

  1. Open terminal inside project folder.

  2. Move to laravel directory

cd laravelBackend54
  1. Install dependencies by type
composer install
  1. Copy (.env.example) file into (.env) (Create a new file named .env).

  2. Create a database on your MySQL Server

  3. Open (.env) file and change the database configs like DB_DATABASE , DB_USERNAME , and DB_PASSWORD to match your system database environment.

  4. Run

php artisan key:generate

in terminal to set the application APP_KEY.

  1. Run
php artisan vendor:publish --provider="Codecasts\Auth\JWT\ServiceProvider"

in terminal to publish Codecast Laravel JWT

  1. 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
  1. Run Migration php artisan migrate

  2. Run development server php artisan serve or php artisan serve --port=PORT for custom port

NodeJS + Express Server

  1. Open terminal inside project folder.

  2. Move to express directory

cd expressBackend
  1. Install dependencies by type
npm install
  1. 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')
  1. open terminal and run the server by type node index.js

Testing

Currently unit testing just available for LaravelServer

to run test type vendor/bin/phpunit on (laravelBackend54) folder

jwtbackends's People

Contributors

faruqisan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.