go-auth-api

module
v0.0.0-...-78dacf9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: MIT

README ยถ

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
  • Docker
  • Docker Compose
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
  1. Build and run the application using Docker Compose:

    docker-compose up --build -d
    
  2. Access the API at http://localhost:8080.

  3. Access the SMTP at http://localhost:1080.

Running Locally

To run the application locally without Docker:

  1. Ensure you updated the docker-compose.yml and config.yml files as comments suggest it !

  2. Generate the swagger documentation :

    swag inti -g cmd/api/main.go
    

    or

    swag init -d ./cmd/api/ --pdl 3
    
  3. Ensure PostgreSQL and MailDev are running:

    docker-compose up db smtp -d
    
  4. 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

  1. To run tests, use the following command:

    go test ./test/service
    

Directories ยถ

Path Synopsis
cmd
api command
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
app
dto
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL