Project developed at the "Digital Innovation One - Eduzz Fullstack Developer #2" bootcamp.
Table of Contents
A microservice API to authenticate, generate JWT token and CRUD users.
Project developed for educacional purposes.
Finished.
- npm
npm install npm@latest -g
- PostgreSQL
-
Clone the repo
git clone https://github.com/MarioDoncel/microservice-authentication-node
-
Install NPM packages
npm install
-
Run on PostgreSQL the queries that are in database.sql to create a database "application_user", the necessary tables and the admin user.
-
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
-
Run the application
npm run play
BaseURL - http://localhost:3000
-
/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 -> 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" }
-
/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
-
/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" }
-
/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
Distributed under the MIT License. See LICENSE.txt
for more information.
Mario Andres Doncel Neto
Email - 88mario.doncel@gmail.com
Whatsapp - +55 19 99612 9909
Project Link: https://github.com/MarioDoncel/microservice-authentication-node