Authentication API
A JWT Authentication Service API built with Go, Gin, and Gorm.
๐ Features
- User registration and login
 
- JWT-based authentication
 
- Password reset via email
 
- Token blacklisting for logout
 
- Swagger documentation
 
๐ ๏ธ Setup
Prerequisites
Environment Variables
Create a .env file with the following content:
APP_ENVIRONMENT=development
APP_HOST=localhost:8080
# Database configuration for PostgreSQL
DATABASE_HOST=db # 'db' with docker-compose, 'localhost' if in local
DATABASE_PORT=5432
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_NAME=go-auth-db
# SMTP configuration
SMTP_HOST=smtp # 'smtp' with docker-compose, 'localhost' if in local
SMTP_PORT=1025
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_FROM=no-reply@example.com
# JWT secret
JWT_SECRET={secret}
Configuration
Edit configs/config.yaml to configure jwt and group settings.
Running the Application
- 
Build and run the application using Docker Compose:
docker-compose up --build -d
 
- 
Access the API at http://localhost:8080.
 
- 
Access the SMTP at http://localhost:1080.
 
Running Locally
To run the application locally without Docker:
- 
Ensure you updated the docker-compose.yml and config.yml files as comments suggest it !
 
- 
Generate the swagger documentation :
swag inti -g cmd/api/main.go
or
swag init -d ./cmd/api/ --pdl 3
 
- 
Ensure PostgreSQL and MailDev are running:
docker-compose up db smtp -d
 
- 
Run the application:
go run cmd/api/main.go
 
Swagger Documentation
Access the Swagger UI at http://localhost:8080/swagger/index.html.
๐ API Endpoints
Auth
POST /{UUID}/register - Register a new user 
POST /{UUID}/login - Authenticate a user 
POST /{UUID}/forgot-password - Request a password reset 
POST /{UUID}/reset-password - Reset the user's password 
POST /{UUID}/logout - Logout a user (protected) 
GET /{UUID}/me - Get user profile (protected) 
Health
GET /{UUID}/health - Check the health of the service 
USer
GET /{UUID}/users - Check the health of the service 
DELETE /{UUID}/remove-users - Check the health of the service 
๐งช Running Tests
- 
To run tests, use the following command:
go test ./test/service