Skip to content

DanielMil/Authentication-Server

Repository files navigation

Simple Authentication Service

This application is intended to be a bootstrap or proof of concept for designing a containerized authentication microservice. The server is easy to run and configure, and currently supports user registration, login, sessions, password recovery and JWT.

Installation

Clone

  • Clone this repo to your local machine using https://github.com/DanielMil/Authentication-Server

Configure

Create a .env file for your configurations in the root directory. Copy the following configuration and edit appropriately.

# MongoDB connection
MONGO_URI = mongodb://mongo:27017/<database>

# When running locally.
# MONGO_URI = mongodb://localhost:27017/<database>

# Email credentials for forgotten password email reset
EMAIL_ADDRESS = <email> 
EMAIL_PASSWORD = <password>

# Secrets for JWT and Express-Session.
# Secrets should be a random, private string.
JWT_SECRET = <secret>
SESSION_SECRET = <secret>

With Docker (Recommended)

Build and Run

docker-compose up --build

Manually

Ensure that TypeScript, Node.js, tsc and MongoDB are installed on your machine.

Install dependencies.

npm install

Compile the TypeScript into JavaScript.

tsc

Start your Mongo database with any method you wish.

Run the server.

npm start
npm run dev # Runs server with nodemon

Endpoints

Register

POST /auth/register

Body

Response

Login

POST /auth/login

Get Current User

GET /auth/user

Update User

PUT /auth/user

Delete User

DELETE /auth/user

Logout

POST /auth/logout

Forgot Password

POST /auth/password/forgotPassword

Reset Password

POST /auth/password/resetPassword/:resetPasswordToken

Features

  • Endpoints to login, register, logout and get current user in session.
  • Containerized and exposed with Docker.
  • Support user sessions with cookies.
  • JWT Support.
  • Endpoints for updating user, deleting user and forgotten passwords.
  • Change username field to email
  • Refactor all code to use async-await

About

Containerized authentication server for user registration and login. Uses Passport.js and MongoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors