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.
- Host: GitHub
- URL: https://github.com/majid0899/auth-service
- Owner: Majid0899
- Created: 2025-09-24T12:07:58.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-04T10:35:27.000Z (8 months ago)
- Last Synced: 2025-10-04T12:24:34.393Z (8 months ago)
- Topics: expressjs, javascript, jwt, mysql-database, mysql2, nodejs, redis, sequelize, sequelize-orm, tyepscript
- Language: TypeScript
- Homepage:
- Size: 70.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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