jwt-gin

command module
v0.0.0-...-22dfa01 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 4 Imported by: 0

README

Logo

JWT and Gin

An API to manage registration, login and authentication

Technology   |    Project   |    How to Run   |    License

License

Introduction

This repository is an tutorial of how we can use JSON Web Token (JWT) and the Gin framework and in this way we can authenticate registered users. But what is a JWT?

The JSON Web Token is an internet open standard (RFC 7519) for creating optionally signed and/or encrypted data whose payload contains the JSON that asserts some claim numbers. Tokens are signed using a private secret or a public/private key. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA, or ECDSA.

While JWTs can be encrypted to also provide secrecy between parties, we will focus on signed tokens. Signed tokens can verify the integrity of the claims contained within it, while encrypted tokens hide those claims from other parties. When tokens are signed using public/private key pairs, the signature also certifies that only the party that owns the private key is the one who signed it.

✨ Technology

The Project was develop as using the following techs:

💻 Project

As said before, this project is a simple one that only aims to demonstrate how users will be authenticated within our API. So it's a very simple project with endpoints. So for this project, we will need to create 2 public endpoints that will be used as authentication and 1 protected endpoint that will be protected by our JWT. So the in few lines we had

📓 Requirements

As educational project, and the purpose is use the concepts of CRUD, then we requirements of the our applications is to :

  1. Register a User
  2. Login
  3. Authentication

As can be seen above the list of requirements is , in summary, a simple CRUD.

Products Attributes

User Type
ID int
Username string
Password string
CreatedAt datetime
DeletedAt datetime
UpdateAt datetime

End Points

The API has the following end points:

Type url Functionality
get "/api/admin/user" Authenticate the user to see the information
post "/api/register" Register a User
post "/api/login" Login

🚀 How to Run

To run the this project

  • Clone the repo and access the directory;
  • You also need to have a MySQL and create a database and table;
    • The initial configurations can be encounter in .env, it is needed to use configure this instance;
  • Init the instance in localhost: 8000 with go run main.go;
  • If you have docker, you can use the following command:
docker compose --env-file .env  up -d --build

📄 License

The projects is under the MIT license. See the file LICENSE fore more details


Author

Made with ♥ by Rafael 👋🏻

Linkedin Badge Gmail Badge

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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