An open API service indexing awesome lists of open source software.

https://github.com/majid0899/auth-service

a standalone authentication & authorization service. It shows reusable, secure, and production-style code.
https://github.com/majid0899/auth-service

expressjs javascript jwt mysql-database mysql2 nodejs redis sequelize sequelize-orm tyepscript

Last synced: about 2 months ago
JSON representation

a standalone authentication & authorization service. It shows reusable, secure, and production-style code.

Awesome Lists containing this project

README

          

๐Ÿ›ก๏ธ Auth Service

An authentication microservice built with Node.js, Express, and TypeScript, featuring JWT authentication, OAuth (Google & GitHub), Redis session management, and MySQL (via Sequelize) for data persistence.

๐Ÿš€ Features

๐Ÿ” User registration and login with JWT tokens

๐Ÿ” Token refresh and logout endpoints

๐Ÿ‘ฅ Role-based authorization (Admin & User)

๐ŸŒ OAuth 2.0 login with Google and GitHub

๐Ÿ’พ MySQL integration using Sequelize ORM

โšก Rate limiting for login endpoint

๐Ÿง  Written in TypeScript for better type safety

๐Ÿงฉ Modular structure for scalability

โš™๏ธ Installation
1 Clone Repository
git clone https://github.com/Majid0899/auth-service.git
cd auth-service
2 Install dependencies
npm install
3. Configure environment variables
Create a .env file in the root directory and add the following:
# ==============================
# App Configuration
# ==============================
PORT=5000
URL=http://localhost

# ==============================
# Database Configuration (MySQL)
# ==============================
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=rootpassword
DB_NAME=auth_db

# ==============================
# JWT Configuration
# ==============================
JWT_SECRET=
JWT_REFRESH_SECRET=

# ==============================
# Redis Configuration
# ==============================
REDIS_URL=

# ==============================
# OAuth Configuration
# ==============================
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:3000/api/auth/google/callback

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GITHUB_CALLBACK_URL=http://localhost:3000/api/auth/github/callback

# ==============================
# Rate Limiting
# ==============================
MAX_ATTEMPTS=5
BLOCK_TIME=900

๐Ÿง‘โ€๐Ÿ’ป Development
Start the development server
npm run dev
Production
npm run build
npm start

๐Ÿงฉ API Endpoints
๐Ÿ”ธ Authentication Routes (/api/auth)

Register User
POST /api/auth/register

Request Body:{
"name": "John Doe",
"email": "john@example.com",
"password": "Password123!",
"phone": "1234567890",
"role": "user"
}

Login User
POST /api/auth/login

Request Body:{
"email": "john@example.com",
"password": "Password123!"
}

Refresh Token
POST /api/auth/refresh

Request Body:{
"refreshToken": ""
}

Logout User
POST /api/auth/logout

Request Body:

{
"refreshToken": ""
}

Get Profile (Protected)

GET /api/auth/profile
Headers: Authorization: Bearer

List All Users (Admin Only)

GET /api/auth/users
Headers: Authorization: Bearer

๐Ÿ”น OAuth Routes (/api/auth)
Method Endpoint Provider Description
GET /google Google Redirects to Google login
GET /google/callback Google OAuth callback with access & refresh tokens
GET /github GitHub Redirects to GitHub login
GET /github/callback GitHub OAuth callback with access & refresh tokens

| Category | Technology |
| -------------- | -------------------------------- |
| Runtime | Node.js (TypeScript) |
| Framework | Express.js |
| Database | MySQL (Sequelize ORM) |
| Cache/Session | Redis |
| Authentication | JWT + Passport (Google & GitHub) |
| Security | bcrypt, dotenv |
| Utilities | Nodemon, ts-node, rate limiter |

๐Ÿค Contributing

Fork the repository

Create a new branch (git checkout -b feature/your-feature)

Commit your changes (git commit -m "Add new feature")

Push to your branch (git push origin feature/your-feature)

Open a Pull Request

๐Ÿงพ License

This project is licensed under the ISC License.

๐Ÿ“ฌ Author

Majid Khan
๐Ÿ’ผ GitHub

๐Ÿ“ง Email: your.email@example.com