auth-go

command module
v0.0.0-...-6898076 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 10 Imported by: 0

README

auth-go

This is a Go-based web application that provides user authentication and management services. It uses the Gin framework for routing and handling HTTP requests, and PostgreSQL for the database.

Features

  • User Authentication:
    • Register new users
    • Login with email and password
    • Logout
    • Password reset
    • Email verification
  • OAuth 2.0:
    • Login with third-party providers (e.g., Google, Github)
  • User Management:
    • Get user information
    • Update user information
    • Delete users
  • JWT Support:
    • Uses JSON Web Tokens for secure API authentication

Getting Started

Prerequisites
  • Go 1.16+
  • PostgreSQL
  • Git
Installation
  1. Clone the repository:
    git clone https://github.com/Jonathan0823/auth-go.git
    
  2. Install dependencies:
    go mod tidy
    
  3. Set up the database:
    • Create a PostgreSQL database
    • Set the environment variables in a .env file (see Configuration section)
  4. Run the application:
    go run main.go
    

Usage

The application exposes a RESTful API for user authentication and management.

API Endpoints
  • POST /api/auth/register: Register a new user
  • POST /api/auth/login: Login with email and password
  • POST /api/auth/logout: Logout the current user
  • POST /api/auth/refresh: Refresh the JWT token
  • POST /api/auth/forgot-password: Request a password reset
  • POST /api/auth/reset-password: Reset the password
  • GET /api/auth/verify/email: Verify the user's email
  • POST /api/auth/verify/email/resend: Resend the email verification link
  • GET /api/auth/:provider: Initiate OAuth 2.0 login with a provider
  • GET /api/auth/:provider/callback: Handle the OAuth 2.0 callback
  • GET /api/user/me: Get the current user's information
  • GET /api/user/:id: Get user information by ID
  • GET /api/user/get-all: Get all users
  • GET /api/user/email: Get user information by email
  • PATCH /api/user/update: Update the current user's information
  • DELETE /api/user/delete/:id: Delete a user by ID

Configuration

The application is configured using environment variables. Create a .env file in the root of the project with the following variables:

DB_HOST=localhost
DB_PORT=5432
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=your_db_name
DB_SSL=disable

PORT=8080

JWT_ACCESS_SECRET=your_jwt_access_secret
JWT_REFRESH_SECRET=your_jwt_refresh_secret

ALLOWED_ORIGINS=http://localhost:3000

EMAIL=your_email_service
PASSWORD=your_email_password

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_gihub_client_secret

GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client-secret
BASE_URL=http://localhost:8080

SESSION_SECRET=your_session_secret
ENVIRONMENT=development

Dependencies

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package config provides configuration and database initialization for the application
Package config provides configuration and database initialization for the application
internal
errors
Package errors provides a set of error types and functions for handling errors in the application.
Package errors provides a set of error types and functions for handling errors in the application.
handler
Package handler provides HTTP handlers for user authentication and management
Package handler provides HTTP handlers for user authentication and management
middleware
Package middleware provides middleware functions for authentication and OAuth handling in a Gin web application.
Package middleware provides middleware functions for authentication and OAuth handling in a Gin web application.
models
Package models provides data models for the application
Package models provides data models for the application
repository
Package repository is the main repository package that provides access to all repositories and transaction management.
Package repository is the main repository package that provides access to all repositories and transaction management.
routes
Package routes provides route registration for the application
Package routes provides route registration for the application
service
Package service provides business logic for user authentication and management
Package service provides business logic for user authentication and management
Package utils is a utility package that provides functions for program's utility operations
Package utils is a utility package that provides functions for program's utility operations

Jump to

Keyboard shortcuts

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