Authentication service with local and OAuth (Google) authentication support.
- Local authentication (email/password)
- Google OAuth integration
- Password reset functionality
- Email verification
- JWT-based authentication
- Role-based access control (RBAC)
- Predefined roles and permissions
- Rate limiting
- CORS support
The project includes HTTP request files (api.http) in the src/interfaces/routes directory for testing endpoints:
auth.api.http: Authentication-related endpointsapp.api.http: General application endpointstest.api.http: Test endpoints for protected routes
- Node.js 20+
- pnpm
- Docker and Docker Compose
-
Clone the repository
-
Install dependencies:
pnpm install
-
Copy
.env.exampleto.envand update the variables -
Build and start the Docker containers:
pnpm docker:build pnpm docker:dev
-
After the containers are running, you need to grant database permissions. Connect to the MySQL container and execute the following commands:
docker exec -it authcore_mysql_db mysql -uroot -p
Important
When prompted, enter the root password from your .env file.
-
Once inside MySQL, execute these commands:
GRANT ALL PRIVILEGES ON *.* TO 'MYSQL_USER'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;
Important
Remember to change MYSQL_USER for the user you're going to use.
-
Exit MySQL:
exit
-
Run the Prisma migrations and seed the database:
pnpm prisma:generate pnpm prisma:migrate:dev pnpm prisma:seed
pnpm dev: Start development serverpnpm build: Build the projectpnpm start: Start production serverpnpm docker:build: Build Docker containerspnpm docker:dev: Start Docker containerspnpm docker:down: Stop Docker containerspnpm docker:logs: View Docker container logspnpm prisma:generate: Generate Prisma clientpnpm prisma:migrate:dev: Run database migrationspnpm prisma:migrate:reset: Reset databasepnpm prisma:migrate:rollback: Rollback last migrationpnpm prisma:seed: Seed the database with initial data
-
PORT: Server port number (default: 8000)PORT="8000" -
NODE_ENV: Environment (development/production)NODE_ENV="development" -
APP_NAME: Name of your applicationAPP_NAME="AuthCore" -
COMPOSE_PROJECT_NAME: Docker Compose project nameCOMPOSE_PROJECT_NAME="authcore_server" -
ALLOWED_ORIGINS: Comma-separated list of allowed origins for CORSALLOWED_ORIGINS="http://localhost:3000,https://yourdomain.com" -
API_URL: Base URL for the API endpointsAPI_URL="http://localhost:8000/api/v1"
-
DATABASE_URL: MySQL connection URLDATABASE_URL="mysql://user:password@localhost:3306/database" -
MYSQL_USER: MySQL userMYSQL_USER="user" -
MYSQL_PASSWORD: MySQL passwordMYSQL_PASSWORD="password" -
MYSQL_ROOT_PASS: MySQL root passwordMYSQL_ROOT_PASS="root_password" -
MYSQL_DB: MySQL database nameMYSQL_DB="authcore" -
MYSQL_PORT: MySQL port (default: 3306)MYSQL_PORT="3306"
-
JWT_SECRET: Secret key for access tokensJWT_SECRET="your-jwt-secret" -
JWT_REFRESH_SECRET: Secret key for refresh tokensJWT_REFRESH_SECRET="your-jwt-refresh-secret"
-
SMTP_HOST: SMTP server hostSMTP_HOST="smtp.gmail.com" -
SMTP_PORT: SMTP server portSMTP_PORT="587" -
SMTP_SECURE: Whether to use TLS (true for port 465, false for port 587)SMTP_SECURE="false" -
SMTP_USER: SMTP username/emailSMTP_USER="your-email@gmail.com" -
SMTP_PASSWORD: SMTP password or app-specific passwordSMTP_PASSWORD="your-password"
-
GOOGLE_CLIENT_ID: Google OAuth client IDGOOGLE_CLIENT_ID="your-client-id" -
GOOGLE_CLIENT_SECRET: Google OAuth client secretGOOGLE_CLIENT_SECRET="your-client-secret" -
GOOGLE_CALLBACK_URL: OAuth callback URLGOOGLE_CALLBACK_URL="http://localhost:8000/api/v1/auth/google/callback"
To obtain the Google OAuth credentials, follow these steps:
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Click on "Create Credentials" and select "OAuth client ID"
- Select "Web application" as the application type
- Add a name for your OAuth client
- Add authorized JavaScript origins:
http://localhost:8000 - Add authorized redirect URIs:
http://localhost:8000/api/v1/auth/google/callback - Click "Create"
- Copy the generated Client ID and Client Secret
- Update your
.envfile with these values:GOOGLE_CLIENT_ID="your-client-id" GOOGLE_CLIENT_SECRET="your-client-secret" GOOGLE_CALLBACK_URL="http://localhost:8000/api/v1/auth/google/callback"
Note
Make sure to enable the Google+ API in your Google Cloud Console project before using OAuth.
The system comes with the following predefined roles:
-
SUPER_ADMIN
- Full system access
- All permissions
-
ADMIN
- Elevated access
- Most permissions except system configuration
-
MANAGER
- Resource management capabilities
- Create, read, update, manage, and approve permissions
-
USER
- Basic access
- Read-only permissions
-
AUDITOR
- System audit capabilities
- Read and audit permissions
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request