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.
- 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
- Go 1.16+
- PostgreSQL
- Git
- Clone the repository:
git clone https://github.com/Jonathan0823/auth-go.git
- Install dependencies:
go mod tidy
- Set up the database:
- Create a PostgreSQL database
- Set the environment variables in a
.envfile (see Configuration section)
- Run the application:
go run main.go
The application exposes a RESTful API for user authentication and management.
POST /api/auth/register: Register a new userPOST /api/auth/login: Login with email and passwordPOST /api/auth/logout: Logout the current userPOST /api/auth/refresh: Refresh the JWT tokenPOST /api/auth/forgot-password: Request a password resetPOST /api/auth/reset-password: Reset the passwordGET /api/auth/verify/email: Verify the user's emailPOST /api/auth/verify/email/resend: Resend the email verification linkGET /api/auth/:provider: Initiate OAuth 2.0 login with a providerGET /api/auth/:provider/callback: Handle the OAuth 2.0 callbackGET /api/user/me: Get the current user's informationGET /api/user/:id: Get user information by IDGET /api/user/get-all: Get all usersGET /api/user/email: Get user information by emailPATCH /api/user/update: Update the current user's informationDELETE /api/user/delete/:id: Delete a user by ID
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- Gin: HTTP web framework
- pq: PostgreSQL driver
- jwt-go: JSON Web Token implementation
- goth: OAuth 2.0 library
- godotenv: Environment variable loader
- validator: Input validation
- sessions: Session management
- gomail: Email sending
This project is licensed under the MIT License - see the LICENSE file for details.