Skip to content

Auth service using JWT and Express for user authentication

Notifications You must be signed in to change notification settings

Gguardiola/auth-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth-service

This service acts as middleware for the rest of the services that require authentication.

You can also visit the rest of the services that are part of this project:

Microservices architecture diagram (Boira v1)

Getting started guide

I have developed this service to be part of my microservices architecture to implement a token authentication system (JWT) in any other project I do.

API routes

Signup

  POST /auth/signup

Request body:

{
    "email": "test@test.com",
    "username": "John",
    "lastname": "Doe",
    "birthday": "1990-10-10",
    "password": "123476789"
}

Response body:

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

Login

  POST /auth/login

Request body:

{
    "email": "test@test.com",
    "password": "123476789"
}

Response body:

{
    "success": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI0NzQ0NWE4OS02ZjcyLTQ5NjctYmM2Ny03YjA1M2ZjMDEyYjkiLCJpYXQiOjE3MDQyNDQzMzcsImV4cCI6MTcwNDQxNzEzN30.f5D1BvD0qGKI8sELSO2ehzePxfM1RAcwKWdqCAXQ9_s"
}

NOTE: the token should be stored (e.g. browser cookies/local storage).

Logout

  POST /auth/logout
Header Type Value
Authentication token Required. User's token

Response body:

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

After the logout, the token will be added to a blacklist until the expiration date (48h).

Additional information

Once the user successfully login, the auth service will provide a JWT token that will be valid for 48 hours or until the user logs out. The token has the user id encrypted that will be checked using a middleware on every API call (see the microservices diagram above).

Authentication error response

If an authentication token is missing, malformed, or invalid, you will receive an HTTP 401 Unauthorized response code.

About

Auth service using JWT and Express for user authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published