jwt-authentication-API

command module
v0.0.0-...-6119ed1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README ยถ

๐Ÿงฉ jwt-authentication-API

Welcome to our JWT Authentication project! This repository serves as a demonstration of how to implement JSON Web Token (JWT) authentication in a Go web application, making your applications secure and user-friendly. We are Glen Maritim and Naniwet Maritim.

๐Ÿ“‘ Table of Contents

๐Ÿ”ญ Overview

Are you ready to supercharge your Go web applications with robust authentication? Look no further! Our project showcases the power of JWT authentication, providing features such as user registration, login, and protected routes. We've leveraged the flexibility of GORM as the ORM library and the blazing-fast Gin framework to create a seamless user experience.

โœจ Features

  • User Registration: Allow users to sign up effortlessly by providing a username and password.
  • User Login: Enable users to access their accounts securely with their credentials.
  • Authentication Middleware: Safeguard your routes with JWT token verification, ensuring only authenticated users gain access.
  • Password Hashing: Protect user passwords using bcrypt hashing, making them virtually impossible to crack.
  • JWT Generation and Validation: Generate JWT tokens upon successful login and validate them for authenticated routes.
  • Database Integration: Seamlessly interact with a PostgreSQL database using GORM, ensuring efficient storage and retrieval of user information.

๐Ÿ“‹Requirements

To get started, ensure you have the following prerequisites installed:

  • Go (version 1.15 or higher)
  • PostgreSQL (version 9.6 or higher)

๐Ÿ› ๏ธ Installation

  1. Clone the repository:

    git clone https://github.com/Reliccode/jwt-authentication-API.git
    
  2. Navigate to the project directory:

    cd jwt-authentication-API
    
  3. Install dependencies:

    go mod tidy
    
  4. Set up the PostgreSQL database:

    Execute the SQL script located in database.sql to initialize the required tables.

  5. Configure the database:

    Update the database configuration in config/config.go with your PostgreSQL database credentials.

  6. Run the application:

    go run main.go
    

Voila! Your application is now up and running on http://localhost:8080.

๐Ÿ’ป Usage

  1. Register a new user:

    Send a POST request to /api/register with the following JSON payload:

    {
        "email": "youremail",
        "password": "yourpassword"
    }
    
  2. Log in:

    Log in with the registered user credentials by making a POST request to /api/login with the same JSON payload.

  3. Access protected routes:

    Upon successful login, you will receive a JWT token in the response. Use this token to access protected routes by including it in the Authorization header of your requests:

    Authorization: Bearer your-jwt-token
    

๐Ÿ“ API Endpoints

  • POST /signup: Register a new user.
  • POST /login: Log in and receive a JWT token.
  • GET /validate: Get the profile of the currently logged-in user (protected route).

๐Ÿ“œ License

This project is licensed under the MIT License. For more details, check out the LICENSE file.

๐Ÿ™Œ Acknowledgments

A big shoutout to the fantastic tools and libraries that made this project possible:

๐Ÿ–‹๏ธ Authors

๐Ÿค Contributing

See CONTRIBUTING.md for guidelines.


Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

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