Skip to content

MarioDoncel/microservice-authentication-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authentication Microservice API


Project developed at the "Digital Innovation One - Eduzz Fullstack Developer #2" bootcamp.


MIT License LinkedIn


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact
  6. Acknowledgments

About The Project

A microservice API to authenticate, generate JWT token and CRUD users.

(back to top)

Built With

(back to top)

Objective

Project developed for educacional purposes.

(back to top)

Status

Finished.

(back to top)

Getting Started

Prerequisites

  • npm
    npm install npm@latest -g
  • PostgreSQL

Installation

  1. Clone the repo

    git clone https://github.com/MarioDoncel/microservice-authentication-node
  2. Install NPM packages

    npm install
  3. Run on PostgreSQL the queries that are in database.sql to create a database "application_user", the necessary tables and the admin user.

  4. Configure your access to database, your pgcrypto key and JWT secret key on .env

     # POSTGRE DB
     PGUSER=postgres
     PGHOST=localhost
     PGPASSWORD=xxxxxx
     PGDATABASE=nodeauth 
     PGPORT=5432
     
     ADMINPASSOWRDKEY=xxxxx
    
     JWT_SECRET_KEY=xxxxx
  5. Run the application

    npm run play

(back to top)

Usage

ROUTES

Token

POST:

  • /token -> Made a basic authentication of the user and generate a JWToken that returned in the response:

    • Basic Auth:
        Username: admin
        Password: admin
    
  • /token/validate -> Made validation of the JWToken and returns 'OK' in the response:

    • Bearer Auth:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    

Users

GET:

  • /users -> Authenticate the requesting user and return all users

    • Bearer:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    
    • Response:
       [
         {
           "uuid": "a7961cb9-9442-47d4-86d5-b2bb3bd904a8",
           "username": "admin"
         },
         {
           "uuid": "f50a2ee3-405e-49e2-87fa-732b72f57425",
           "username": "Mario Andres Doncel Neto"
         }
       ]
  • /users/:uuid -> Authenticate the requesting user and return a single user found by :uuid

    • Bearer:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    
    • Response:
      {
         "uuid": "a7961cb9-9442-47d4-86d5-b2bb3bd904a8",
         "username": "admin"
       }

POST:

  • /users -> Authenticate the requesting user, create a new user and return the uuid created

    • Bearer:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    
    • Body:
      {
         "username": "Mario Andres Doncel Neto",
         "password": "1234"
       }
    • Response:
      fa1e45cc-9649-493b-aa91-6a25e94b5e22
    

PUT:

  • /users/:uuid -> Authenticate the requesting user, update the user found by :uuid and return this user data in response

    • Bearer:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    
    • Body:
      {
         "username": "Mariana Fanaro",
         "password": "1234"
      }
    • Response:
     {
        "uuid": "fa1e45cc-9649-493b-aa91-6a25e94b5e22",
        "username": "Mariana Fanaro"
     }

DELETE:

  • /users/:uuid -> Authenticate the requesting user, delete the user found by :uuid and return 'OK' in the response

    • Bearer:
        eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjQwNzE4ODgzLCJleHAiOjE2NDA
        4OTE2ODMsInN1YiI6ImE3OTYxY2I5LTk0NDItNDdkNC04NmQ1LWIyYmIzYmQ5MDRhOCJ9.5IXoH_GQKWNQF4YE8CXZ6a1f4GiUFcW-zL-xtuF_7s4
    
    • Response:
     OK
    

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Mario Andres Doncel Neto

Email - 88mario.doncel@gmail.com
Whatsapp - +55 19 99612 9909

Project Link: https://github.com/MarioDoncel/microservice-authentication-node

(back to top)

Acknowledgments

(back to top)

About

An API RESTFUL microservice of authentication using JWT

Topics

Resources

License

Stars

Watchers

Forks