Skip to content

Json web token introduction with slides and working nodeJS server

License

Notifications You must be signed in to change notification settings

benjaminW78/json-web-token-introduction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-web-token-introduction

Build Status Dependency Status devDependency Status

Json web token introduction with slides and working nodeJS server

The MIT License (MIT)

Table of Contents

Introduction
Practical information
Files tree
Installation
Nodejs api documentation
Acknowledgement
Other project

Introduction

This repository is intended introduce you to JWT via this presentation, JWT you will love it more than your parents and with a working nodejs example based on jsonwebtoken npm package.

Practical information

You must be familiar with :

Files tree

.
├── app                               // folder containing nodejs App example
│   ├── server
│   │   ├── db
│   │   │   ├── conf.js
│   │   │   ├── dbConnection.js
│   │   │   └── wtfKeyJwt.js
│   │   ├── env.js
│   │   ├── handlers.js
│   │   ├── index.js
│   │   ├── npm-debug.log
│   │   └── router
│   │       └── routes.js
│   └── vendors
├── package.json                      // npm install file
└── sql_request                   
    └── testDb                        // Db postgresql export

Installation

  $ git clone git@github.com:benjaminW78/json-web-token-introduction.git
  // Go inside the new folder
  $ npm i
  // connect to postgres via shell
  $ sudo -u postgres psql

  // create Db for futur import
  postgres=# CREATE DATABASE test;

  // Import postgresql Db stored inside sql_request folder
  postgres=# test < 'path_to_this_repo/json-web-token-introduction/sql_request/testDb';

  // set your user to use this table.
  postgres=# \connect test;
  postgres=# GRANT ALL PRIVILEGES ON TABLE users TO yourUserPostGres;
  postgres=# \q;

  // start nodejs Server with nodemon instance.
  $ npm run start
  

Nodejs api documentation

This section show you which paths of your nodejs server are availble.

Create Token

  // GET METHOD 
  http://localhost:8080/api/createToken
  // request body: JSON OBJECT
  {
    "fsn":"toto@gmail.com", // db valid user email
    
    "jwt_duration":1 , // JWT valid duration in minutes
    
    "iss":"whatYouWant" // remove this key/value if you want your server to create jwt with his
                        // own issuer value, because
                        // when you will verify your previously created jwt, the server will test it with 
                        // its own issuer value not the one you created your jwt 
  }

Verify Token

  // GET METHOD 
  http://localhost:8080/api/verifyToken
  // request body 
  T = yourTokenToTest
  // request body: empty {}

Acknowledgement

Thanks to @Companeo for making me work on this problem.

Other projects

You may also like those projects:

About

Json web token introduction with slides and working nodeJS server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published