Skip to content

Jonathan0823/auth-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

182 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A starter Go REST API boilerplate with built-in authentication, including JWT-based sessions and OAuth 2.0 integration. Designed for scalability and ease of customization in modern web applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors