Skip to content

This is simple microservice for JWT Authentication with NodeJS & MongoDB.

Notifications You must be signed in to change notification settings

asepmaulanaismail/jwt-auth-nodejs-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Authentication Microservice with NodeJS & MongoDB

This is simple microservice for JWT Authentication with NodeJS & MongoDB.

How to Use

Running with Node & Nodemon

git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
node server.js

or

git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
nodemon server.js

Running with Docker

See how to install docker.

git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
sudo docker build -t jwt-auth-nodejs:latest .
sudo docker run -d -p 8080:8080 jwt-auth-nodejs

API List:

Basic Route

Route to show a random message

GET: localhost:8080/

Response:

Hello! The API is at http://localhost:8080/api

Setup

Create a simple user

GET: localhost:8080/setup

Response:

{
    "success": true
}

Authenticate

Route to authenticate a user

POST: localhost:8080/api/authenticate

Params:

{
    "username": "asepmaulanaismail",
    "password": "asep123!!",
    "deviceId": "1"
}

Response:

{
    "success": true,
    "message": "Enjoy your token!",
    "token": "<YOUR TOKEN HERE>"
}

Basic API

Route to show a random message

GET: localhost:8080/api

Params:

{
    "token": "<YOUR TOKEN HERE>",
    "deviceId": "1",
    "username": "asepmaulanaismail"
}

Response:

{
    "message": "Welcome to the coolest API on earth!"
}

Verify API

Verify token

POST: localhost:8080/api/verify

Params:

{
    "token": "<YOUR TOKEN HERE>",
    "deviceId": "1",
    "username": "asepmaulanaismail"
}

Response:

{
    "success": true,
    "message": ""
}

Users API

Route to return all users

GET: localhost:8080/api/users

Params:

{
    "token": "<YOUR TOKEN HERE>",
    "deviceId": "1",
    "username": "asepmaulanaismail"
}

Response:

[
    {
        "_id": "5a5862d28c16852c84d79d78",
        "username": "asepmaulanaismail",
        "password": "asep123!!",
        "admin": true,
        "__v": 0
    }
]

Logout API

Logging out

POST: localhost:8080/api/logout

Params:

{
    "token": "<YOUR TOKEN HERE>",
    "deviceId": "1",
    "username": "asepmaulanaismail"
}

Response:

{
    "success": true,
    "message": ""
}

About

This is simple microservice for JWT Authentication with NodeJS & MongoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published