lord-tx / golang-jwt-project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang JWT Authentication Project

Introduction

This project is a simple Golang application that showcases best practices for user and admin authentication using JSON Web Tokens (JWT).

Features

  • User and admin authentication using JSON Web Tokens (JWT).
  • Secure user registration with password hashing.
  • Authorization middleware to protect routes.
  • Role-based access control (user and admin roles).
  • Flexible configuration options.

Getting Started

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • Go
  • MongoDB or another preferred database system.

Installation

Clone the repository:

git clone https://github.com/your-username/your-golang-jwt-project.git
cd your-golang-jwt-project
go mod tidy
go run main.go

Usage

Authentication

  • Obtain an authentication token by sending a POST request to /auth with valid credentials (username and password).
  • Include the obtained JWT token in the Authorization header for protected routes.

User Registration

  • Register a new user by sending a POST request to /register with user details.
  • New users will be assigned the "user" role by default.

Admin Privileges

  • To access admin-only routes, a user must have the "admin" role.
  • Admins can be assigned manually through the database or using an admin endpoint (if implemented).

Configuration

You can configure the project by modifying the .env file or using environment variables. Refer to CONFIGURATION.md for detailed configuration options.

Contributing

We welcome contributions from the community. To contribute to this project, please follow our Contributing Guidelines.

License

This project is licensed under the MIT License. See LICENSE.md for details.

About


Languages

Language:Go 100.0%